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"
}
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 _ids are always returned.