综合技术

nodejs/mongodb – reading out one specific element

微信扫一扫,分享到朋友圈

nodejs/mongodb – reading out one specific element
0

I want to read out one specific element out of mongodb

db.collection('profiles', function(err, collection) {
    collection.findOne({'email': mail}, function(err, item) {

this reads the whole entry

for example:

{
  "email" : "asdd@asd.de",
  "password" : "asd",
  "_id" : ObjectId("51c8790f912501e403000001")
}

how can i read out only one of those elements

for example password

{
  "password" : "asd"
}

Problem courtesy of: Pika

Solution

collection.findOne({'email': mail}, {password: 1, _id: 0}, function(err, item) {
}

The second argument to find
/ findOne
is the fields to select(projection). {_id: 0}
is explicitly required because by default _id
s are always returned.

Solution courtesy of: c.P.u1

阅读原文...


微信扫一扫,分享到朋友圈

nodejs/mongodb – reading out one specific element
0

Node.js Recipes

把撒哈拉沙漠变成一个太阳能农场,这可能吗?

上一篇

A step-by-step guide to agnostic UX personas — free downloadable

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

nodejs/mongodb – reading out one specific element

长按储存图像,分享给朋友