简体   繁体   English

从mongodb node js搜索记录时出现问题?

[英]Problems in searching records from mongodb node js?

I am trying to search my mongodb database and get the columns that contains the search key. 我正在尝试搜索mongodb数据库,并获取包含搜索键的列。 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. 我的目标是只在Trialkey等于我输入的值的收款列中返回文档。 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. 它将找到每个文档,并且只会返回apikey。 You want to do: 您想做:

dbi.collection("trial").find({apikey: retrieveapikey})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM