node.js - Mongodb not returning specific fields -


i trying return 1 field sessions document.

i'm using current query (it returns entire document):

yield users.findone({     '_id': id // var id holds object id objectid("560ae1dc53cb3222679430f1") }, {     '_id': 0, // <--- being ignored     'sessions': 1 // <--- being ignored }); 

i tried in mongo shell , works should:

db.users.find({"_id":objectid("560ae1dc53cb3222679430f1")},{"sessions":1,"_id":0}).pretty() // <--- works 

i'm using co-monk based off of mongoskin. should work.

not made clear in documentation, there explicit key name syntax "options" object :

yield users.findone({ '_id': id }, { 'fields': { '_id': 0, 'sessions': 1  }}); 

so works bit differently mongodb shell api. same applies other options such sort.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -