我如何使用Java修改Mongo DB

时间:2018-07-24 12:51:44

标签: java database mongodb testing

如何在mongo db中更新此数据库的“版本”部分?香港专业教育学院试图创建一个新的集合,但无法使其工作,有什么想法吗?集合本身的名称是document_revisions

{
    "_id" : ObjectId("5afaa7fd3c670aa8c2bf9f08"),
    "type" : "PP",
    "revision" : {
        "date" : "2018-05-23T10:50:20.798Z",
        "version" : "1.4.23"
    },
    "location" : "https://www.tetst.com/privacy-policy/"
}

我尝试了这个,但是不认为这是我需要做的

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

    //Version ID
    Double version = "version";

    // Remove Game from DB
    MongoClientURI connectionString = new MongoClientURI("mongodb://" + mongoConectionAddress + "/sportdec_platform?socketTimeoutMS=300000");
    @SuppressWarnings("resource")
    MongoClient mongoClient = new MongoClient(connectionString);
    MongoDatabase database = mongoClient.getDatabase("sportdec");
    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 个答案:

没有答案