I'm trying to update a set of matching records using updateAll, but I'm getting "MongoError: unknown operator: $or"
VideoTag is model that simply has a videoId and tagId. I'm getting a list of tagIds that I want to replace with with another tagId:
Tag.prototype.merge = function (tagIds, cb) {
var where = {
'or': _.map(tagIds, function (id) {return {tagId: id}})
}
logger.debug("where:", where)
//
// This is just to test the where clause...it succeeds
//
VideoTag.find({where: where})
.then(function (res){
logger.debug('found videoTags:', res)
})
//
// This fails
//
VideoTag.updateAll({where: where}, {tagId:targetId})
.then(function () {
logger.debug("updated videoTags")
})
.catch(function (err) {
logger.warn(err)
})
// ...
}
I used VideoTag.find() to test if my were clause was right and I get the expected results... but updateAll simply throws an error...
debug output:
tag DEBUG - where: { or: [ { tagId: '55133adcca81f8163212646f' } ] }
loopback:connector:mongodb all +2ms videoTag { where: { or: [ [Object] ] } }
loopback:connector:mongodb updateAll +0ms videoTag { where: { or: [ [Object] ] } } { tagId: 53a7602229545775ba2ab90c }
loopback:connector:mongodb MongoDB.parseUpdateData +0ms { tagId: 53a7602229545775ba2ab90c }
loopback:connector:mongodb all +1ms videoTag { where: { or: [ [Object] ] }, order: [ 'id' ] } null [ { _id: 55133adcca81f81632126475,
videoId: 55133adcca81f81632126468,
tagId: 55133adcca81f8163212646f } ]
tag DEBUG - found: [ { videoId: 55133adcca81f81632126468,
tagId: 55133adcca81f8163212646f,
id: 55133adcca81f81632126475 } ]
loopback:connector:mongodb updateAll.callback +1ms videoTag { where: { '$or': [ [Object] ] } } { '$set': { tagId: 53a7602229545775ba2ab90c } } { [MongoError: unknown operator: $or]
name: 'MongoError',
message: 'unknown operator: $or',
index: 0,
code: 2,
errmsg: 'unknown operator: $or' } undefined
tag WARN - MongoError: unknown operator: $or