findAndModify fails with error: "Cannot update 'field1' and 'field1' at the same time

后端 未结 1 798
长情又很酷
长情又很酷 2021-01-12 23:27

I\'m trying to build MongoDB Java findAndModify query.

The main purpose is that I would like to set _id in insert query by myself.

Here is m

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 00:06

    The essential problem here is this:

    db.collection.update(
       { "type": "group" },
       { 
          "$set": { "mygroup": "value" }
          "$setOnInsert" { "mygroup": "value" }
       }
    )
    

    Which is basically what you are trying to do.

    You cannot address the same field in a $set operation as a $setOnInsert operation.

    There is a general problem in the logic that causes the error you are experiencing.

    0 讨论(0)
提交回复
热议问题