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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

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