Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Node Mongo-查找多个参数_Node.js_Mongodb - Fatal编程技术网

Node.js Node Mongo-查找多个参数

Node.js Node Mongo-查找多个参数,node.js,mongodb,Node.js,Mongodb,我试图在集合中查找是否已经有会话号,以避免重复。dadosORS.email和dadosORS.sessao(即3)来自一个表单。所以当我这样做的时候: mongoClient.collection('registosORS', function(err,collection){ collection.find({email:{$eq:dadosORS.email}},{sessao:{$eq:dadosORS.sessao}}).toArray(function(err,result){

我试图在集合中查找是否已经有会话号,以避免重复。dadosORS.email和dadosORS.sessao(即3)来自一个表单。所以当我这样做的时候:

mongoClient.collection('registosORS', function(err,collection){
  collection.find({email:{$eq:dadosORS.email}},{sessao:{$eq:dadosORS.sessao}}).toArray(function(err,result){

                    try{
                    console.log(result);
                    }catch (err){
                      console.log(err);                          
                    }

                      if(result){
                        // callback(false)
                        return
                      } else {
我得到的结果=未定义。如果我将查询更改为

 collection.find({email:dadosORS.email},{sessao:dadosORS.sessao}).toArray(function(err,result){
它列出了我的每一封电子邮件:

      [ { _id: 5a37b4c3da53ff1e825f94b4, sessao: '1' },
{ _id: 5a37b4e6da53ff1e825f94b6, sessao: '1' },
    { _id: 5a37b57ce500ca1ea5522e22, sessao: '2' } ]

那么,如何查看该dadosORS.email的dadosORS.sessao是否已经存在?

只需执行
查询:

 collection.find( { email : dadosORS.email, sessao : dadosORS.sessao } )
或者可以表示为

 collection.find( { $and: [ { email : dadosORS.email }, { sessao : dadosORS.sessao } ] } )