mongodb - How do I pass a Mongod field selector to a JavaScript function -
i have basic question can't seem find answer to, hope can out!
i trying create javascript function return specific result mongodb collection. function has 2 arguments, 1 selector within collection , other 1 field needs retrieved.
returnorganisation = function (id, property){ return published.findone({_id:id}).property }
the id parameter work
return published.findone({_id:id}).name;
but when trying add property parameter following error:
update failed: mongoerror: '$set' empty. must specify field so: {$mod: {: ...}}
so question is: how pass property return (for instance, .name of object in collection) function?
i'm sure should not hard do, can't seem work. in advance.
use bracket notation syntax access property this:
returnorganisation = function (id, property_name){ var result = published.findone({_id:id}); return result[property_name]; }
Comments
Post a Comment