简体   繁体   中英

In nodejs collection.find() is not fetching values from Mongodb collection.It returning nothing

 app.get('/render', function(req, res) { MongoClient.connect(dburl, function(err, db) { if (err) throw err; var collection = db.collection('shopping_list'); collection.find().toArray(function(err, result) { res.send({result :result}); }); db.close(); }); }); 
In nodejs collection.find() is not fetching values from Mongodb collection.It returning nothing In nodejs collection.find() is not fetching values from Mongodb collection.It returning nothing

exports.index = function(req, res) {
var queryObj = {};
UserModel.find(queryObj)
.exec(function(err, users) {
    if (!users) {
        console.log("users not found");
    }
    if (!err) {
        console.log("number of users",users.length);
    } else {
        console.log("err",err);
    }
});

};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM