如何使用Java在Mongo DB中获取数字并将其更新为下一个最高数字

时间:2018-07-23 15:49:54

标签: java database mongodb testing

我正在尝试更新数据库以增加mongoDB内部版本号的更改。

{    "_id" : ObjectId("5afaa7fd3c670aa8c2bf9f08"),
"type" : "PP",

"revision" : {

    "date" : "2018-05-23T10:50:20.798Z",

    "version" : "1.4.23"

},

"location" : "https://www.tester.com/privacy-policy/"

}

我目前有这个,但它不起作用:

public void update_privacy()引发异常{

    //Privacy ID
    String privacy_id = "5afaa7fd3c670aa8c2bf9f08";

    //Version ID
    Double version = "version";

    MongoClientURI connectionString = new MongoClientURI("mongodb://" + mongoConectionAddress + "/tester_platform?socketTimeoutMS=300000");
    @SuppressWarnings("resource")
    MongoClient mongoClient = new MongoClient(connectionString);
    MongoDatabase database = mongoClient.getDatabase("tester");
    MongoCollection<Document> collection = database.getCollection("document_revisions");
    collection.find(eq("_id", new ObjectId(privacy_id))).first();
    collection.find(eq("version", new ObjectId()));


    collection.updateOne(version, version+1);


}

0 个答案:

没有答案