lundi 23 juillet 2018

How to get a number and update it with the next highesy number in Mongo DB using java

Im trying to update a database to increase change a version number inside a 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/"

}

I currently have this but its not working:

public void update_privacy() throws Exception {

    //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);


}

Aucun commentaire:

Enregistrer un commentaire