简体   繁体   中英

Mongo node js query implicit $and

It should only update and return results that have match on the request data.

it should be not mutually exclusive (ie if one query does not match then do not return result results)

is using implicit $and a solution to that ?

Query

  keystone.list('Vehicle').model.update({ $or: [{ Body: { $in: req.body.data[0].body } }, { Model: { $in: req.body.data[0].model } }, { Make: { $in: req.body.data[0].make } }, { Year: { $in: req.body.data[0].year } }] }, {
                    $set: {
                        'Summer_Sale_Event': req.body.summer_sale_value
                    }
                }, {
                    'multi': true
                }).exec(function (err, result) {

                });

Request data

Request : [ { body: [ 'Convertible' ],
    make: [ 'Chevrolet' ],
    year: [ '2005' ],
    model: [ 'Corvette' ] } ]

$or means that only one of the condition have to be true. You should be using $and instead.

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