Document field names can't start with '$' (Bad Key: '$set')
问题 BasicDBObject u = new BasicDBObject(); DBObject q = new BasicDBObject(); q.put("orgId", orgId); u.append("orgId", orgId); if(accounts.keySet().size() > 0) { BasicDBObject setObj = new BasicDBObject(); for (String key : accounts.keySet()) { String fieldToUpdate = "accounts." + key; setObj.append(fieldToUpdate, accounts.get(key)); } u.append("$set", setObj); } DBCollection collection = db.getCollection(collectionName); WriteResult result = collection.update(q, u, true, false); I get following