在数组MongoDB中查找内容
我正在用Mongoose
使用Mongoose
。
我有这两个模式:
var feedSchema = mongoose.Schema({ users: [{ type: Schema.Types.ObjectId, ref: 'User' }] ... ... });
和
var userSchema = mongoose.Schema({ email: String, ... ... });
我想查找包含user._id
在其users
字段中的所有提要。
我想知道mongoose
是否有这样的东西:
Feed .find({ users : { $has : [ user._id ] } }) .exec(function(err, retData) { /* SOMETHING */ });
我在文档中找不到像这样的东西。
谢谢!
尝试这个:
Feed.find( { users: user._id } ).exec(...)