The document shows I can use $addToSet to add an element to document when it does not exists.But I am not sure it could use to add Map type to a document.
For Example:
public static void AddToSet(DBCollection collection, Map conditions, String key, Object value) {
BasicDBObject so = new BasicDBObject();
so.putAll(conditions);
collection.update(so, new BasicDBObject("$addToSet", BasicDBObjectBuilder.start().add(key, value)));
}
I deliver value a HashMap will it works?
If so will it lead to performance problem or not recommend?Why?
If you just want to set/add that field/key to that value you shouldn’t use $addToSet but simply $set.
It is the same as if your document was Map and you want to and a new key/value, except it is done on the server.