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
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
Post a Comment