Uw addVocabToList() implementatie ziet er ongeveer zo uit:
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));
Die code zal:
- Zoek het document met name=
listName - Voeg de waarde toe van
newVocabTermnaar determsreeks - Voeg de waarde toe van
newDefinitionnaar dedefinitionsreeks - Retourneer het bijgewerkte document (dit deel is optioneel)