简体   繁体   English

在数组MongoDB中查找内容

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM