[英]Find content inside array MongoDB
I'm using Mongoose
with NodeJS
. 我在
NodeJS
使用Mongoose
。
I have these two schemas: 我有以下两种模式:
var feedSchema = mongoose.Schema({
users: [{ type: Schema.Types.ObjectId, ref: 'User' }]
...
...
});
and 和
var userSchema = mongoose.Schema({
email: String,
...
...
});
I want to find all feeds that contains the user._id
inside its users
field. 我想在其
users
字段中查找包含user._id
所有提要。
I'm wondering if mongoose
has something like this: 我想知道
mongoose
是否有这样的东西:
Feed
.find({
users : {
$has : [
user._id
]
}
})
.exec(function(err, retData) { /* SOMETHING */ });
I couldn't find anything like that in the docs. 我在文档中找不到类似的内容。
Thanks! 谢谢!
尝试这个:
Feed.find( { users: user._id } ).exec(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.