【发布时间】:2015-11-17 16:05:59
【问题描述】:
我在使用 Mongoose 查询 MongoDB 数据库时遇到问题。
我似乎无法弄清楚为什么 .find 查询在以下脚本中被跳过。
'use strict';
// var apnagent = require('./notificationmodule/_header')
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var NotificationSchema = new Schema({
userId: String,
beachId: String,
deviceId: String,
message: String,
notificationSent:{ type: Boolean, default: false},
notificationSentDate: Date,
notificationCreated: {type: Date, default: Date.now},
});
var Notifications = mongoose.model('Notification', NotificationSchema);
console.log("Script Started")
Notifications.find({}, function (err, result){
console.log(result);
console.log("This Callback never gets evaluated");
});
console.log("Script Finished")
查询本身似乎没有根据日志进行评估,“this...evaluate”语句永远不会被记录。在研究 Mongoose 的文档后,我发现该查询现在显然是可行的,但即使在 .find({}) 请求中添加 .then 似乎也无法评估查询。谁能告诉我我在这个例子中做错了什么,或者发布一个查询表达式应该是什么样子的例子?
【问题讨论】:
-
尝试给出一些查找条件..
-
感谢您的建议。事实证明,这似乎没有什么不同。空的 .find({}) 也应该返回所有文档。我觉得我以前做过这个,但是将代码发布到衬线我错过了任何东西。
标签: node.js mongodb mongoose mongodb-query