Giter Club home page Giter Club logo

Comments (10)

mafintosh avatar mafintosh commented on June 4, 2024

Yes. You should be able to do something like:

db.myCollection.insert(docs, {continueOnError:true}, callback);

from mongojs.

hamedabdy avatar hamedabdy commented on June 4, 2024

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.

mafintosh avatar mafintosh commented on June 4, 2024

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.

hamedabdy avatar hamedabdy commented on June 4, 2024

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.

hamedabdy avatar hamedabdy commented on June 4, 2024

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.

mafintosh avatar mafintosh commented on June 4, 2024

Thats awesome! Fell free to reopen this issue if the problem occurs again.

from mongojs.

damienromito avatar damienromito commented on June 4, 2024

The problem now is : the param "docs" is equal to "null" when there is an error. How to get all inserted objects?

from mongojs.

hamedabdy avatar hamedabdy commented on June 4, 2024

When there is no error the doc param contains all your documents. (Please do correct me if I'm wrong)

from mongojs.

damienromito avatar damienromito commented on June 4, 2024

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.

hamedabdy avatar hamedabdy commented on June 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.