I am trying to search my mongodb database and get the columns that contains the search key. However, when I run my program, its brings all the columns. What could I be doing wrong? My goal is to only return documents in the collection train where trialkey is equal to the value I enter. Not all the documents.
app.get('/getdata',function(req,res){
console.log("Entering here");
var retrieveapikey = req.query.apiKey;
console.log("retriever",retrieveapikey);
/* dbi.collection("trial").find({},{"apikey":retrieveapikey}).toArray(function(err, result) {
if (err) throw err;
console.log(result.length);
for(var i=0;i<result.length;i++){
delete result[i]._id;
}
console.log(typeof (result));
res.send(result);
//dbi.close();
});*/
dbi.collection("trial").find({},{"apikey":retrieveapikey}).toArray(function(err, result) {
console.log(result);
});
});
dbi.collection("trial").find({}, {"apikey":retrieveapikey})
That will find every document and will only return the apikey. You want to do:
dbi.collection("trial").find({apikey: retrieveapikey})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.