In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article comes from my own blog: www.wangerbao.com
Bulk Write Operations operation is a new feature of mongodb3.2. The syntax is as follows:
Db.collection.bulkWrite ([,...], {writeConcern:, ordered:})
Among them, ordered is a place to pay attention to, according to the official description:
The default is ture, that is, the data is inserted sequentially. If there is an error in the middle, the execution will not continue.
In the case of false, mongo inserts data concurrently, and errors in the middle have no effect on subsequent operations.
Examples are as follows
Initialize data, initialize 3 items
> db.log.count () 0 > db.log.bulkWrite ([. {insertOne: {"document": {"_ id": 1, "char": "Dithras", "class": "barbarian", "lvl": 4},... {insertOne: {"document": {"_ id": 2, "char": "Dithras", "class": "barbarian") "lvl": 4},... {insertOne: {"document": {"_ id": 3, "char": "Dithras", "class": "barbarian", "lvl": 4}.], {ordered:true}) {"acknowledged": true, "deletedCount": 0, "insertedCount": 3, "matchedCount": 0, "upsertedCount": 0, "insertedIds": {"0": 1, "1": 2, "2": 3} "upsertedIds": {} > db.log.count () three
Order default: true, if the second data primary key conflicts, only the first data will be inserted, and the total data amount is 4.
The second data primary key conflict Only one piece of data > db.log.bulkWrite ([. {insertOne: {"document": {"_ id": 4, "char": "Dithras", "class": "barbarian", "lvl": 4},... {insertOne: {"document": {"_ id": 2, "char": "Dithras", "class": "barbarian") is inserted. "lvl": 4},... {insertOne: {"document": {"_ id": 5, "char": "Dithras", "class": "barbarian", "lvl": 4}.], {ordered:true}) 2017-04-10T17:48:37.960+0800 E QUERY [thread1] BulkWriteError: write error at item 1 in bulk operation: BulkWriteError ({"writeErrors": [{"index": 1, "code": 11000 "errmsg": "E11000 duplicate key error collection: c_log.log index: _ id_ dup key: {: 2.0}", "op": {"_ id": 2, "char": "Dithras" "class": "barbarian", "lvl": 4}}], "writeConcernErrors": [], "nInserted": 1, "nUpserted": 0, "nMatched": 0 "nModified": 0, "nRemoved": 0, "upserted": []}) BulkWriteError@src/mongo/shell/bulk_api.js:372:48BulkWriteResult/this.toError@src/mongo/shell/bulk_api.js:336:24Bulk/this.execute@src/mongo/shell/bulk_api.js:1173:1DBCollection.prototype.bulkWrite@src/mongo/shell/crud_api.js:191:20@ (shell): 1:1 > db.log.count () four
Order is changed to false, and the first data primary key conflicts. If there is no problem with 2 or 3 items, the total data amount is 6.
> db.log.bulkWrite ([. {insertOne: {"document": {"_ id": 4, "char": "Dithras", "class": "barbarian", "lvl": 4},... {insertOne: {"document": {"_ id": 6, "char": "Dithras", "class": "barbarian") "lvl": 4},... {insertOne: {"document": {"_ id": 5, "char": "Dithras", "class": "barbarian", "lvl": 4}.], {ordered:false}) 2017-04-10T17:49:36.539+0800 E QUERY [thread1] BulkWriteError: write error at item 0 in bulk operation: BulkWriteError ({"writeErrors": [{"index": 0, "code": 11000 "errmsg": "E11000 duplicate key error collection: c_log.log index: _ id_ dup key: {: 4.0}", "op": {"_ id": 4, "char": "Dithras" "class": "barbarian", "lvl": 4}}], "writeConcernErrors": [], "nInserted": 2, "nUpserted": 0, "nMatched": 0 "nModified": 0, "nRemoved": 0, "upserted": []}) BulkWriteError@src/mongo/shell/bulk_api.js:372:48BulkWriteResult/this.toError@src/mongo/shell/bulk_api.js:336:24Bulk/this.execute@src/mongo/shell/bulk_api.js:1173:1DBCollection.prototype.bulkWrite@src/mongo/shell/crud_api.js:191:20@ (shell): 1:1 > db.log.count () six
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.