按标题、用户名(user模型)、平台名称(platform模型) 进行搜索, 怎么做关联搜索呢?
下面代码有问题,搜索不到数据:
var kw = /关键词/;
var conditions = {$or: [{"title": kw}, {"username.name": kw}, {"platname.name": kw}]};
var query = model.find( conditions ).populate({
path: 'platname',
select: 'name'
}).populate({
path: 'username',
select: 'name'
});
query = query.sort(sort).skip(start).limit(pagesize);
query.exec(function (err, results) {});
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.Types.ObjectId;
var timerSchema = new Schema({
mode: Number,
username: {type: ObjectId, ref: 'user'},
platname: {type: ObjectId, ref: 'platform'},
time: String,
title: String,
state: {
type : Number,
default : 1
}
});
// user模型
var userSchema = new Schema({
name: {
type: String,
unique: true
},
pwd: String,
email: {
type: String,
unique: true
}
});
// platform模型
var platSchema = new Schema({
name: {
type: String,
unique: true
},
account:{
type: String,
unique: true
},
pwd: String
});
\n```