Wednesday, 17 May 2017

Search through Mongoose "OR" for fields in which there are incoming elements of an array of _id (MongoDB id)

I have situation: Need find all rows which field (example block_id) contains any element of array with mongodb _id's .

block_category.find({name: 'text'}).exec((err,b_ids)=>{
   // b_ids its array of mongodb ids
   users.find( {$or:[
                        {'block_ids1':{$in:b_ids}},
                        {'block_ids2':{$in:b_ids}}
                    ]}).exec((err,users)=>{
      /* users is empty 
       but if i find via command line with ObjectID("id") its look fine(
      I try let array =  users.map(function(o){ return new mongoose.Types.ObjectId(o); }); and than find by {$in:array} - nothing

      */

   })
})

Whats wrong ?



via Melixion

No comments:

Post a Comment