简体   繁体   中英

Find content inside array MongoDB

I'm using Mongoose with NodeJS .

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.

I'm wondering if mongoose has something like this:

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(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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