The array result shows like following
[
{
_id: 56fe444d6ce2226431f5388c,
name: 'admin',
email: '[email protected]',
password: '$2a$10$Wz34L5QZ6ACQIP.Q2WOJLuOSvs0aHQbSO1bhhOpiiXDOaN/AIF8U2',
occasiontype: 'Anniversary',
date: Mon Apr 18 2016 00:00:00 GMT+0530 (India Standard Time),
__v: 0
}
]
node.js
router.post('/find-registry', function(req, res){
var uEmail = req.body.email;
var findUserId = function(db, callback) {
var cursor =db.collection('users').find({email:uEmail}).toArray(function(err, docs){
if(err){
callback(new Error("Some problem"));
} else {
callback(null,docs);
}
});
};
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
findUserId(db, function(err,docs) {
db.close();
console.log(docs);
});
});
});
Here the console.log(docs) showing the result of array. But there i need only name. How do i get it? I tried like console.log(docs[name]) but it showing undefined.
.findOne()instead.docs[0].namewill give you name of first json packet in arraydocs[0].namethen i got the result. Thank u.