query returning selected properties of object

9 views
Skip to first unread message

CCVonLewin

unread,
May 8, 2013, 4:02:13 AM5/8/13
to node-mong...@googlegroups.com
Greetings,
Can one specify select properties of an object to be returned in a find?

DB OBJ:
{ id: N, name: X, color: Z }

cursor.findOne( {"id": N}, {"select":["color"]}, function ( err, result ) { 
    console.log( result );
 });
 
In the above, the idea is that "result" would only contain { color: Z } rather then the entire object.

Best <
Carl

Jonathan Ong

unread,
May 8, 2013, 6:21:25 PM5/8/13
to node-mong...@googlegroups.com
that's what the "fields" option is for

Aaron Heckmann

unread,
May 9, 2013, 12:50:22 PM5/9/13
to node-mong...@googlegroups.com
Here's the docs for findOne with details on the "fields" option. http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#findone


--
You received this message because you are subscribed to the Google Groups "node-mongodb-native" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-na...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Aaron


CCVonLewin

unread,
May 10, 2013, 8:01:47 PM5/10/13
to node-mong...@googlegroups.com
Excellent, thank you. I feel slightly silly asking after having looked over the github docs again under querying.
Reply all
Reply to author
Forward
0 new messages