I have a collection in mongoDB called 'roomlist'. Using the command line, i can run db.roomlist.find()
and it will return the correct data. Example:
> db.roomlist.find()
{ "_id" : ObjectId("56a5d3b07bf609f092e7f9ab"), "name" : "Lobby", "type" : "public", "lock" : 0, "owner" : "Mike", "invites" : "all", "__v" : 0 }
However, in my node.js app, it just returns empty. If I console log the output, I get:
[]
Here's what I'm using:
My schema is as follows:
RoomSchema = new Schema({
name: String,
type: String,
lock: String,
owner: String,
invites: String, created: {
type: Date,
default: Date.now
}
});
And then I define Roomlist as follows:
var Roomlist = db.model('Roomlist', RoomSchema);
I'm trying to retrieve a list of all "rooms" in the collection and send it as an object to one of my views. Here's what I've got for that:
Roomlist.find({},{}, function(err, docs) {
if(err) throw err;
res.render('index.ejs',{
"roomlist": docs,
csrfToken: req.csrfToken()
});
console.log(docs);
});
I have the console.log in there for testing, since I can't seem to get it to work. I have other schemas set up in the same file that are using the same approach, and they seem to work just fine. Could anyone tell me what I'm doing wrong here?