the array result shows following
[ { _id: 56fe444d6ce2226431f5388c, name: 'admin', email: 'admin@gmail.com', 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 console.log(docs)
showing result of array. there need name. how it? tried console.log(docs[name])
showing undefined.
you can -
docs[0].name
you have access first object inside docs array , access name attribute of object.
update
you use findone() method instead , access name attribute -
docs.name
Comments
Post a Comment