Mongodb-java's two basic operations Upsert and Insertmany

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.