Querying after populate in Mongoose

后端 未结 6 2088
悲&欢浪女
悲&欢浪女 2020-11-21 16:17

I\'m pretty new to Mongoose and MongoDB in general so I\'m having a difficult time figuring out if something like this is possible:

Item = new Schema({
             


        
6条回答
  •  一个人的身影
    2020-11-21 16:40

    @aaronheckmann 's answer worked for me but I had to replace return doc.tags.length; to return doc.tags != null; because that field contain null if it doesn't match with the conditions written inside populate. So the final code:

    query....
    .exec(function(err, docs){
       docs = docs.filter(function(doc){
         return doc.tags != null;
       })
       // do stuff with docs
    });
    

提交回复
热议问题