For your first problem, MongoDB has upsert , so
db.collection.update(
{query for id},
{document},
{upsert: true}
)
or in the Java driver
yourCollection.update(searchObject, modifiedObject, true, false);
If you want to set a user identifier, just set the key _idmanually, i.e.
yourBasicDBObject.put("_id",yourCustomId)
you just have to make sure that it is unique to each document.
You also need to install _idin yours modifiedObject, otherwise a new one will be generated.
As for bulk operations , only setting a user identifier for each document with a key should also work _id.
source
share