Mongodb return old collection

后端 未结 3 2051
甜味超标
甜味超标 2021-01-24 13:05
router.post(\'/orders/finish\', function(req, res, next) {
var order_id = req.body.order_id;
var user_id  = req.body.user_id;
var table_id = \'\';

var result = [];



m         


        
3条回答
  •  醉酒成梦
    2021-01-24 13:21

    You should wait for the update to complete before calling find

    db.collection('tables').update({id: table_id, status: true}, {$set: {status: false}}, function(err, result) {
            assert.equal(null, err);
            var cursorTables = db.collection('tables').find({status: false});
            cursorTables.forEach(function(doc, err) {
                assert.equal(null, err);
                resultTables.push(doc);
            }, function() {
                db.close();
            });
        });
    

提交回复
热议问题