This article is just to record a few basic operations, first Upsert, there are several methods can be done, but all need to specify Updateoptions.upsert (true), the simplest method is as follows (Eqq is a filter to the Bson, For specific usage, see previous article):
Dbcoll.replaceone (EQQ ("_id", Y.get ("_id")), Y, New UpdateOptions (). Upsert (True))
Next is Insertmany, in the Insertmany, if the occurrence of Dup-key will lead to error, the entire list is not inserted successfully, but I think most people need is even if there is a duplicate key and other problems are inserted successfully, only this duplicate does not insert , you need to add a insertmanyoptions () with the following command. Ordered (false):
Dbcoll.insertmany (Reslist, New Insertmanyoptions (). Ordered (false))
Mongodb-java's two basic operations Upsert and Insertmany