【MongoDB 6.0】MongoInvalidArgumentError: Update document requires atomic operators

1. Problems

An error occurred while updating the values ​​of the following files:

{
    
    
    _id: ObjectId("63a950274d8bb6ad92cac680"),
    articleid: '100000',
    content: '晚上造房子',
    userid: '1002',
    datetime: ISODate("2022-12-26T07:41:27.033Z"),
    likenum: 10,
    state: null
  }

The wrong command used was:

db.comment.updateOne({
    
    userid:"1002"}, {
    
    likenum: NumberInt(1002)})

Error:
report error


Two, solve

With partial modification :

db.comment.updateOne({
    
    userid:"1002"}, {
    
    $set:{
    
    likenum: NumberInt(1002)}})

The modification was successfully completed without error:
success

Guess you like

Origin blog.csdn.net/weixin_45800258/article/details/128445842