codeofnode
codeofnode

Reputation: 18619

mongodb query with mongoose in any Objectid

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

Upvotes: 0

Views: 336

Answers (1)

Neil Lunn
Neil Lunn

Reputation: 151112

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

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

});

Upvotes: 1

Related Questions