Comments (10)
Yes. You should be able to do something like:
db.myCollection.insert(docs, {continueOnError:true}, callback);
from mongojs.
Here is my code, I have already tested that option but nothing.
db.concerts.insert(data, {continueOnError: true, safe: true}, function(err, docs){
console.log('err: ' + err + ' docs:' + docs);
if(!err) console.log('data inserted successfully!\n');
});
from mongojs.
If I run something equivalent to your script I get
err: null docs:[object Object],[object Object],[object Object]
data inserted successfully!
Is that not the expected output?
from mongojs.
I have this application that I have to insert a large sum of data with unique ids into database. In this array of data there might be some duplicate documents. but I what I expect from insert
is even if there are duplicates it continues on inserting the rest of data.
but this what I get:
err: MongoError: E11000 duplicate key error index: test.concerts.$_id_ dup key: { : "3541691" } docs:undefined
and so it wouldn't insert the rest.
from mongojs.
Sorry for the bother, but the problem seems to solved. I really don't know how, but it is.
If that is ok with you, I'll keep you posted if any further problems of this kind would occur.
Thanks for the fast reply 👍
I also put the working code, just in case.
db.concerts.insert(data, {continueOnError: true, safe: true}, function(err, docs){
console.log('err: ' + err);
if(!err) console.log('data inserted successfully!\n');
});
from mongojs.
Thats awesome! Fell free to reopen this issue if the problem occurs again.
from mongojs.
The problem now is : the param "docs" is equal to "null" when there is an error. How to get all inserted objects?
from mongojs.
When there is no error the doc
param contains all your documents. (Please do correct me if I'm wrong)
from mongojs.
You're right, but in my case, I have errors cause I insert duplicated objects. I use the option {continueOnError:true} to not stop the insertion, but I cannot get all inserted object (cause I have one of several error). It's not possible to return object when the option "continueOnError" is setted to true?
from mongojs.
I think it's mostly like every time there is a duplicate key an error is thrown with its cause! Thus you should only get one document for each error!
from mongojs.
Related Issues (20)
- Use native Object.assign instead of xtend HOT 1
- update `var` to `const` - Readme
- How to use collation HOT 2
- updateMany returns an error HOT 1
- Comparison with the official mongodb package
- Is $text supported within find()? HOT 1
- SCRAM-SHA-256 (and more)
- Publish version with mongodb ^3 HOT 3
- how to set remote connection to mongodb HOT 3
- How do i show dbs, similar to shell "show dbs" HOT 1
- Using replicaSet and readPreference option HOT 1
- "failed to connect to server" even after mongodb is back up HOT 1
- Compatible with hapijs 18? HOT 2
- MongoDB Atlas's URI does not work HOT 5
- collection.update no longer usable for overwriting an entry HOT 16
- v2.6.0 up to v3.1.0 update operation error! HOT 5
- .findOne() query just returns undefined on callback HOT 2
- Does this support aws document db?
- Found Vulnerability 'Regular Expression Denial of Service (ReDoS)' in Synk.io
- How to connect to mongo atlas?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongojs.