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

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.