【发布时间】:2019-03-07 00:57:52
【问题描述】:
我会使用 model.find 将在我的数据库中找到的数据传递给一个值。首先,我会 console.log() mongoose 返回的值以确保它是相关值。但是目前,当我在我的 Nodejs 数据库中传递 find query 时,什么也没有发生。不会发生 console.log 或错误。
所以我想知道是什么坏了,如何让这些元素正常工作,得到我的日志,然后是我的价值。
这里是我的 mongoose.model:
const mongoose = require("mongoose");
const Schema= mongoose.Schema;
var ChatSchema = new Schema({
ip:{required:true, type: String},
message: {required:true, type: String},
room:{required:true, type: String}
});
module.exports = mongoose.model("Chat", ChatSchema)
这里是我的 server.js:
var chatScan= Chat.find(ip, function (err, docs) {
if(err) return console.log(err)
return docs.length
})
console.log("chatScan: ", chatScan)
任何提示都会很棒, 谢谢
【问题讨论】:
-
可以是任意数量的东西。连接不正确,
get请求不正确等需要更多代码来确定。 -
连接有效!现在一切正常
-
好吧,现在函数返回给我 mongoose.find() 的函数定义如下
Query { _mongooseOptions: {}, _transforms: [], _hooks: Kareem { _pres: Map {}, _posts: Map {} }, _executionCount: 0,
标签: javascript node.js mongoose