Alessandro Alessandro - 5 months ago 9
Node.js Question

Mongoose find() with function

I want to find an object in my collection which satisfies the following:
getDistance(userDefinedPosition, positionFromDocument) == true.

So I would like to do something like this

Users.find( getDistance(userDefinedPosition, positionFromDocument) == true, function( ... ) )


So userDefinedPosition is value while positionFromDocument is a field from inside a possible match.

Answer

Try the following:

Users.$where(getDistance(userDefinedPosition, this.positionFromDocument)).exec(function( ... ))

See http://mongoosejs.com/docs/2.7.x/docs/finding-documents.html

Comments