-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.2.33
-
Component/s: MongoDB 3.4
-
Environment:mongoDB v3.4.3 (storageEngine is wiredTiger)
mongoose v4.12.4 (depends on mongodb 2.2.33)
node.js v8.8.1
Elementary OS (based on Ubuntu 16.04 LTS)
-
Empty show more show less
I chose bug as issue type. Actually I never know and never make decision about this is a normal behavior or not.
I've gone through official documentations and searched jira platform about this issue but I could not any thing. Forgive me please if I had overlooked somethings.
When using bulk operation with option journaling false it doesn't return `code: 11000` duplicate key error.
When using following options, it *doesn't return* errors:
- `
{ j:false }
`
- `
{ w:0, j:false }
`
When using following options, it *returns* `duplicate key` errors:
- `
{ w:"majority", j:false }
`
- `
{ w:0, j:true }
`
- `
{ w:"majority", j:true }
`
Code for example:
var ObjectId = mongoose.Types.ObjectId, User = require('./models/user') let bulk = User.collection.initializeUnorderedBulkOp() let doc1 = { "branch" : "DUPLICATE", "department" : ObjectId("582bf1d8322809041e667777"), } let doc2 = { "branch" : "TEST_SUCCESS", "department" : ObjectId("582bf1d8322809041e668888"), } let doc3 = { "branch" : "DUPLICATE", "department" : ObjectId("582bf1d8322809041e669999"), } bulk.insert(doc1) bulk.insert(doc2) bulk.insert(doc3) let bulkOptions = { w:0, j:false // next run change argument j as true } bulk.execute(bulkOptions, (err, result) => { let writeErrors = result.toJSON().writeErrors for (let i = 0; i > writeErrors.length - 1; i++) { let error = writeErrors[i] debug(error.toString()) } })
Additionally the schema of User model has an unique compound index as `userSchema.index(
{ branch:1, department:1 },
{ unique: true })`