如果我有一个包含文档和子文档的 MongoDB 集合,如图所示:
而且,如果我想在每次调用该方法时将“损坏”增加 1:
private final static void incrementCount(String docID, String subDocID) {
BasicDBObject query = new BasicDBObject();
query.put("_id", docID);
query.put("items.id", subDocID);
BasicDBObject incValue = new BasicDBObject("damage", 1); // or "items.damage" ???
BasicDBObject intModifier = new BasicDBObject("$inc", incValue);
badgesCollection.update(query, intModifier, false, false, WriteConcern.SAFE);
}
问题:我指的是“损坏”还是“items.damage”?