Monday, 9 September 2013

filter mongodb object result by ObjectId with Underscore

filter mongodb object result by ObjectId with Underscore

I have a problem combining UnderscoreJS and MongooseJS in NodeJS. I have a
result of mongoose and I want filter a array
var __ = require("underscore"),
platformInfo = __.findWhere(user.platforms, {"pId": platformId});
But pId inside user.platforms is a ObjectId and can't find. But if i make
a each and compare like this all its OK:
__.each(user.platforms, function(platform){
if(platform.pId.toString() == platformId){
}
});
How i can find in findWhere method (one line, and cool) the same result?
Thanks

No comments:

Post a Comment