0

I have a schema as follows

var S = new Schems({
  f : Mixed
})

mongoose.model('collection', S);

How do I query the 'collection' such that i find the documents where f is ANY mongo ObjectId?

eg if '

collection' = [{ f: ObjectId('549138f19f52f268c717a8a2'), _id : 1 },
{ f : ObjectId('549139129f52f268c717a8a4'), _id : 2 }, { f : false, _id :3  }  ]

the result should have with _id 1 and 2

1 Answer 1

1

You are asking for the $type operator. ObjectId types are type "7":

Collection.find({ "f": { "$type": 7 } },function(err,docs) {
   // results in here

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.