MongoError: unknown operator: $or

1,520 views
Skip to first unread message

Partap Davis

unread,
Jul 28, 2015, 12:01:05 AM7/28/15
to LoopbackJS
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 targetId = this.id
  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

Partap Davis

unread,
Jul 28, 2015, 12:09:45 AM7/28/15
to LoopbackJS, chee...@gmail.com
BTW, I was using loopback-conn...@1.8.0... I just updated to 1.11.3, but no change

I am running mongodb 2.6.5 

Raymond Feng

unread,
Jul 28, 2015, 11:39:36 AM7/28/15
to loopb...@googlegroups.com
Please note that updateAll() takes a ‘where’ object instead of the full ‘filter’ object. For example,

It should be VideoTag.updateAll(where, {tagId:targetId})


Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/loopbackjs/95b0690f-5b43-4267-8f1d-4c36794e8c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Partap Davis

unread,
Jul 28, 2015, 1:06:18 PM7/28/15
to LoopbackJS, ray...@strongloop.com
I actually thought I had tried that, but I guess not...

Thanks, Raymond!
Reply all
Reply to author
Forward
0 new messages