MongoDB update using Java 3 driver

前端 未结 3 1322
名媛妹妹
名媛妹妹 2020-12-30 03:51

I\'m switching to the MongoDB Java driver version 3. I cannot figure out how to perform an update of a Document. For example, I want to change the \"age\" of an user:

<
3条回答
  •  庸人自扰
    2020-12-30 04:30

    Use:

    coll.updateOne(eq("name", "frank"), new Document("$set", new Document("age", 33)));
    

    for updating the first Document found. For multiple updates:

    coll.updateMany(eq("name", "frank"), new Document("$set", new Document("age", 33)));
    

    On this link, you can fine a quick reference to MongoDB Java 3 Driver

提交回复
热议问题