Din addVocabToList() implementering vil se nogenlunde sådan ud:
MongoCollection<Document> collection = database.getCollection("lists");
Document updatedDocument = collection.findOneAndUpdate(
Filters.eq("name", listName),
new Document("$push",
new BasicDBObject("terms", new BsonString(newVocabTerm))
.append("definitions", new BsonString(newDefinition))),
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
Denne kode vil:
- Find dokumentet med navn=
listName - Tilføj værdien af
newVocabTermtiltermsarray - Tilføj værdien af
newDefinitiontildefinitionsmatrix - Returner det opdaterede dokument (denne del er valgfri)