0
我想传递一个变量申请到Mongo的查询是这样的:范围似乎没有在MongoClient.connect
function retrieveDocNumber(docNumber) {
MongoClient.connect('mongodb://' + this.mongoUrl + "/" + this.mongoDbName, function(error, db) {
var lessonCollection = db.collection('lessons');
if (error) {
console.log(error);
} else {
console.log(docNumber) // Is undefined...
lessonCollection.findOne({number: docNumber}, function(error, doc) {
console.log(error);
console.log(doc);
});
}
});
所以我不能完全肯定这是怎么回事,但docNumber(和任何其他的变量都不会在连接函数中包含范围)在连接函数中是未定义的。任何解决方法或明显的地方,这是错误的?我需要使用用户定义的docNumber从数据库中检索文档。
它不看的docNumber在retrieveDocNumber函数的任何位置进行操作。所以显而易见的是检查函数调用。 –