Reputation: 154
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" : "[email protected]",
"password" : "asd",
"_id" : ObjectId("51c8790f912501e403000001")
}
how can i read out only one of those elements
for example password
{
"password" : "asd"
}
Upvotes: 0
Views: 63
Reputation: 17094
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.
Upvotes: 2