Compatibility of $or and upsert in mongodb

  mongodb, question

Today, I encountered a problem. When I was updating data, I wanted to use the upsert function, and found that the inserted data did not contain the $or part of the filter criteria, as follows:

db.msg.update(
 {
 “type”: “u”,
 “$or”: [
 {“from”: 1, “to”: 2},
 {“from”: 2, “to”: 1}
 ]
 },
 {
 “$push”: {
 “message”: {
 “data”: “holla”,
 “status”: false,
 “time”: new Date()
 }
 }
 },
 true,
 true
 );

It was originally hoped that if it is found that there is no corresponding document in the msg set, the following document should appear in the msg set after execution, for example, the above update (assuming that the document from:1,to:2 does not exist in the current set):

{
 "from": 1,
 "to": 2,
 "type": "u",
 "message": [
 {
 “data”: “holla”,
 “status”: false,
 “time”: ISODate("2014-02-12T01:50:40.866Z")
 }
 ]
 }

However, the actual situation is that the inserted data does not include the condition of $or. Is there any solution?

$upsert currently (2.4) does not support $and and $or, which is said to be supported by 2.6. See official issues: