Mongo返回空结果,即使有记录

时间:2019-04-06 14:29:06

标签: javascript mongodb mongoose

我正在尝试使用以下代码在Mongodb上执行简单查询,但是由于某种原因,我没有从查询中获取数据,即使查询为空也返回0

这是屏幕截图 https://screencast.com/t/r3gJCrW4DvI6

这是我的模型doctor.js

var Schema = mongoose.Schema;
var ObjectId = require('mongoose').Types.ObjectId; 

var doctorSchema = new Schema({
  _id: ObjectId,
  name: String
});

var Doctor = mongoose.model('Doctor', doctorSchema);
module.exports = Doctor;

//module.exports = mongoose.model('doctor', doctorSchema);

这是我使用数据库代码的地方

const Doctor = require('../../model/doctor');

async testconnection() {
    console.log("Start Connection");
    let q = 'local.name : moises';
    console.log("Here: " + await Doctor.find({}).select('name').countDocuments());



//Also I tried this

await Doctor.find({}, function(err, users){
            if (err) throw err;
            // object of all the users
            console.log(users);
        })


await Doctor.find({q}, function(err, users){
            if (err) throw err;
            // object of all the users
            console.log(users);
        })
}

这是终端上的输出

[08:22:22] I/local - Starting selenium standalone server...
[08:22:23] I/local - Selenium standalone server started at http://192.168.60.30:57649/wd/hub
Started
Mongoose default connection open to mongodb://127.0.0.1:27017/local
Start Connection
Here: 0
[]
[]
.


1 spec, 0 failures
Finished in 0.806 seconds```

0 个答案:

没有答案