node.js - $ne query not working with mongoose but working in mongoshell -


when execute mongoose query

financedproject.find({_id:{$ne:fb.financedprojects.financedprojectid}).exec( callback); 

where fb object this

{     _id: objectid("54das4da9dsa9d4ad4a9");     name: "some",     financedprojects: [        {registry:"147", financedprojectid:objectid("13da4sd4sa48da4dsa")},        {registry:"189", financedprojectid:objectid("5d5asd5a4sd5ada5sd")}     ] { 

the result undefined , when execute in mongoshell results expected

because financedprojects array have address element [] like:

financedproject.find({     _id: {         $ne: fb.financedprojects[0|.financedprojectid     } }).exec( callback ); 

edit:

mongoose ist javascript, follows rules of javascript. fb.financedprojects array. if use expression fb.financedprojects.financedprojectid evaluated undefined javascript interpreter, because there no financedprojectid property within array (arrays have 0,1,2,3,... properties). mongoose { $ne: undefined } , has no chance recognize meant property financedprojectid of array elements.

to achieve want, can this:

var arr = []; for( var i=0; i<fb.financedprojects.length; i+=1 ) {     arr.push( fb.financedprojects[i|.financedprojectid ); } financedproject.find({     $not: {         _id: {             $in: arr         }     } }).exec( callback ); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -