mongodb - Mongoose + node.js findOne(), find() not giving results -
i have taken learning node.js few days , facing problem while retrieving data.
i using mongoose in node.js , save() function working when try retrieve data using find() or findone() page keeps loading long time , not give result.
models/chatrooms.js
var mongoose = require('mongoose'); var schema = mongoose.schema; var tblchatroomsschema = new schema({ chatusers: { type: schema.objectid, ref: 'tblchatrooms' }, chatroomid: {type: number, required: true, index: { unique: true }}, // every chat has 1 room id totalmember: number, // indicates total number of members status: number, // 0 = closed, 1 = open created: date, chatlog: string }); module.exports = mongoose.model('tblchatrooms', tblchatroomsschema);
routes.js
> var tblchatrooms = require('./models/tblchatrooms'); > ...... > ...... > > app.get('/member', function (req, res) { > > //res.send("hello world"); > //exit; > if(!req.session.userid){ > res.send('please login chat verified membmers.'); > } > > tblchatrooms.findone({totalmember: 1, status: 1}), function(err, c) { > if(err){ > res.send(err); > } else { > console.log(c); > res.send(c); > }; > }; });
i passing 2 condition find single record.
document have in collection
tblchatrooms
/* 0 */ { "_id" : objectid("546c9a6685ff7dc00d7d3b72"), "chatusers" : objectid("546c58c2fe985f480c008055"), "chatroomid" : 517048, "totalmember" : 1, "status" : 1, "created" : isodate("2014-11-19t13:25:58.410z"), "chatlog" : "empty", "__v" : 0 } /* 1 */ { "_id" : objectid("546c9a7f85ff7dc00d7d3b73"), "chatusers" : objectid("546c58c2fe985f480c008055"), "chatroomid" : 894109, "totalmember" : 1, "status" : 1, "created" : isodate("2014-11-19t13:26:23.114z"), "chatlog" : "empty", "__v" : 0 }
please me solve error
thank you
i'm guessing it's syntax error because don't pass callback. should be:
tblchatrooms.findone({totalmember: 1, status: 1}, function(err, c) {
instead of
tblchatrooms.findone({totalmember: 1, status: 1}), function(err, c) {
Comments
Post a Comment