Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk operations with mongoskin and mongodb 3.x? #194

Closed
pleasantone opened this issue Aug 3, 2016 · 1 comment
Closed

bulk operations with mongoskin and mongodb 3.x? #194

pleasantone opened this issue Aug 3, 2016 · 1 comment

Comments

@pleasantone
Copy link

pleasantone commented Aug 3, 2016

I've read the various bits of literature, and I'm seeing the same problem that the questioner in

http://stackoverflow.com/a/25636911

was seeing.

My code looks like something like this (I wrote it in coffeescript and am converting to js pseudocode):

coll = db.collection('foobar');
bulk = coll.initializeUnorderedBulkOp();
messages.forEach(function(entry) {
    bulk.insert(entry);
});
bulk.execute(function (err, result) {
   if (err) throw err
   inserted += result.nInserted
});
  1. bulk is an object
  2. bulk.insert works just fine
  3. bulk.execute is undefined

The answer in the stackoverflow question said, "only the callback flavor of db.collection() works,
so I tried:

db.collection('foobar', function (err, coll) {
    logger.debug("got here");
    if (err) throw(err);
   bulk = coll.initializeUnorderedBulkOp();
   ... same code as before

We never get to "got here" implying that the "callback flavor" of db.collection() was dropped for 3.0? Unfortunately, my python is way better than my JS prototyping skills, so looking at the skin source code doesn't make any sense to me.

What is the right way, with mongoskin 2.1.0 and the 2.2.0 mongodb JS driver, to do a bulk operation, or is this not implemented at all anymore?

@pleasantone
Copy link
Author

pleasantone commented Sep 3, 2016

Don't do this, use insert with an array of documents instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant