Reputation: 11976
I would pass the found data on my database using model.find to a value. Primarily I would console.log() the value returns by mongoose to ensure it's a relevant value. But currently when I'm passing a find query
in my Nodejs database nothing happens. Neither console.log or error occurs.
So I'm wondering what is broken and how make those element functionning correctly, to get my log, then my value.
here my 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)
here my server.js:
var chatScan= Chat.find(ip, function (err, docs) {
if(err) return console.log(err)
return docs.length
})
console.log("chatScan: ", chatScan)
Any hint would be great, thanks
Upvotes: 0
Views: 82
Reputation: 938
Change server.js
to:
var scannedIp = 12.34.56.78;
var chatScan = Chat.find({ ip: scannedIp }, function (err, docs) {
if(err) return console.log(err)
console.log(docs.length)
})
BTW, the find
method is a promise, so if you want to console.log
it's results outside of the callback, then you need to do something like so:
chatScan.then(docs => {
console.log(docs)
})
Upvotes: 1