regex - MongoDB: cannot upsert if query object and update object contain a same property , 'Cannot apply $addToSet modifier to non-array' -


i want execute complex upsert, made following elements:

  • query on field f regex
  • update of same field f (that specified in query object too)

like this:

db.coll.update({ prop: /valueprop/i } , { $addtoset:{ prop:'a value' }  } , true, false) 

my expectation if document not exist in collection inserted prop field equals 'a value'; in other words should insert document value of prop field 1 specified in update object.

instead throws cannot apply $addtoset modifier non-array , if tries update field prop value specified in query object (that regexp object) instead of using value specified in update object.

isn't bug?

the workaround using $all keyword in query object in following way

db.cancellami.update({prop:{$in:[/regex_value/i]}},{ $addtoset:{prop:'a value'}} ,true,false) 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -