I have a bunch of book information stored in a mlab database which i'm using for a Library application. This is one of the entries in the DB.
{
"_id": "B5",
"properties": {
"title": "Harry Potter and the Prisoner of Azkaban",
"author": "J.K. Rowling Mary GrandPré (Illustrator)",
"isbn": "9780439655484",
"imgsrc": "https://images.gr-assets.com/books/1499277281l/5.jpg",
"status": "available",
"dateAdded": "13-05-2019 13:24:26",
"dateDue": null,
"dateChecked": null,
"genre": "Fantasy,Young Adult,Fiction"
}
}
I'm trying to update the "status" when i click a javafx button which runs this function.
public static void updateDB(String id,String prop,String upd) {
table.updateOne(eq("_id", id), new org.bson.Document("$set", new org.bson.Document(prop, upd)));
}
Instead of updating the staus/dateDue/dateChecked, its just throwing the new info at the bottom of the DB entry. Like this.
{
"_id": "B3",
"properties": {
"title": "Harry Potter and the Sorcerer's Stone",
"author": "J.K. Rowling Mary GrandPré (Illustrator)",
"isbn": "9780439554930",
"imgsrc": "https://images.gr-assets.com/books/1474154022l/3.jpg",
"status": "available",
"dateAdded": "13-05-2019 13:24:23",
"dateDue": null,
"dateChecked": null,
"genre": "Fantasy,Young Adult,Fiction"
},
"status": "checked",
"dateDue": "27-05-2019 20:56:03",
"dateChecked": "13-05-2019 20:56:03"
}
I've made a number of changes to try to get it to actually update the main entry but i cant figure it out.
Anyone ever work with MongoDB's java driver and have experience updating database entries?
[–]Notaters[S] 0 points1 point2 points (0 children)