I am using Nodejs
database, mongodb
. We can use $nin
like this
Model.find({ uname : { $nin : ["sachin","saurav"] } }....
above words for normal elements like uname
and others. But for ids (_id) objects, ..
Model.find({_id : {$nin : ["6534767457dfgbyb23","wtvwt3wy5etvdh"] } } ...
Above the line that does not produce an error, it is displayed correctly.
var ObjectID = require('mongodb').ObjectID; var a = new ObjectID("sdfsdznfsdz"); var b=new ObjectID("sdfjwneufhq2rfwefsd"); Model.find({_id : { $nin : [a,b] } }...
the above also gives no error ...
The problem is that I cannot write manually like a, b, c, d ...
I need to save all these a, b, c, d ... in some variable in some correct format and do it like this:
Model.find({_id : {$nin : variable } }
or
Model.find({_id : {$nin : [variable] } }
I tried this
var string = a+","+b //this didnt work, error : invalid object id var string = "nfw34qfhrs9"+","+"u89tgngnfdb" //this also same error var string = "\"jn4tr43r\"" + "," + "\"ansfuw37fe\"" //this also same error
What should I do? the fact is that I have to get all the elements except those elements with _ids
tags.