You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
doc.save() throw duplicate error after insertMany error insertMany(items,{ordered:false}) if doc is from error.insertedDocs
MongoError: E11000 duplicate key error collection: sharednews.news index: id dup key: { : ObjectId('5fcf184a7ad701402cdb49c7') }
at Function.create (/node_modules/mongodb/lib/core/error.js:57:12)
at toError (/node_modules/mongodb/lib/utils.js:123:22)
at /node_modules/mongodb/lib/operations/common_functions.js:265:39
at handler (/node_modules/mongodb/lib/core/sdam/topology.js:942:24)
at /node_modules/mongodb/lib/cmap/connection_pool.js:350:13
at handleOperationResult (/node_modules/mongodb/lib/core/sdam/server.js:558:5)
at MessageStream.messageHandler (/node_modules/mongodb/lib/cmap/connection.js:277:5)
at MessageStream.emit (events.js:310:20)
at processIncomingData (/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at Socket.ondata (_stream_readable.js:695:22)
at Socket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12) {
driver: true,
index: 0,
code: 11000
}
classNews{// findByFullName() becomes a staticstaticasyncshortMany(items){letinserted=[];try{constinsertResult=awaitthis.insertMany(items,{ordered: false});inserted=insertResult;// works fine}catch({ insertedDocs }){console.log('inserting error');if(insertedDocs){inserted=insertedDocs;// in this docs .save() throw duplicate error}}console.log(inserted.lenght);constresults=awaitasync.eachSeries(inserted,async(item)=>{try{constdata=awaitbitly.shorten(item.link);item.short=data.link;returnitem.save();// throw error if doc is from error.insertedDocs after insertMany}catch(error){console.error('shorting',error);}});returninserted;}}ItemSchema.loadClass(News);
Do you want to request a feature or report a bug?
What is the current behavior?
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered:
doc.save() throw duplicate error after insertMany error
insertMany(items,{ordered:false})
if doc is from error.insertedDocsMongoError: E11000 duplicate key error collection: sharednews.news index: id dup key: { : ObjectId('5fcf184a7ad701402cdb49c7') }
at Function.create (/node_modules/mongodb/lib/core/error.js:57:12)
at toError (/node_modules/mongodb/lib/utils.js:123:22)
at /node_modules/mongodb/lib/operations/common_functions.js:265:39
at handler (/node_modules/mongodb/lib/core/sdam/topology.js:942:24)
at /node_modules/mongodb/lib/cmap/connection_pool.js:350:13
at handleOperationResult (/node_modules/mongodb/lib/core/sdam/server.js:558:5)
at MessageStream.messageHandler (/node_modules/mongodb/lib/cmap/connection.js:277:5)
at MessageStream.emit (events.js:310:20)
at processIncomingData (/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at Socket.ondata (_stream_readable.js:695:22)
at Socket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12) {
driver: true,
index: 0,
code: 11000
}
Do you want to request a feature or report a bug?
What is the current behavior?
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: