meteor-collection2 icon indicating copy to clipboard operation
meteor-collection2 copied to clipboard

Support for bulk inserts

Open rootedsoftware opened this issue 9 years ago • 10 comments

Does this package support bulk insert operations? I have an array of documents (with _id's) and I want to insert them with a single command, but it appears that this isn't supported.

rootedsoftware avatar Apr 23 '15 19:04 rootedsoftware

This package supports whatever Meteor's mongo package supports. I don't think it supports bulk insert.

aldeed avatar Apr 24 '15 22:04 aldeed

It does support bulk inserts. If I remove the schema for this collection Meteor inserts the documents from the array without an issue.

rootedsoftware avatar Apr 26 '15 04:04 rootedsoftware

OK, then we should probably support them, too. It doesn't seem to be a documented feature, though.

aldeed avatar Apr 28 '15 02:04 aldeed

@c316 see https://github.com/meteor/meteor/issues/1255#issuecomment-97276160

I will wait until Meteor officially supports this, but we can keep this issue open to track.

aldeed avatar Apr 29 '15 09:04 aldeed

Any updates on this, I'm getting the error "Error: 0 is not allowed by the schema " when trying to do a bulk insert, and it appears Meteor now fully supports Bulk inserts.

beeekind avatar Feb 10 '16 03:02 beeekind

Agreed. Running into the same issue.

myyellowshoe avatar May 13 '16 16:05 myyellowshoe

+1 on this one :)

nicooprat avatar May 18 '16 13:05 nicooprat

Hi @aldeed is there an interim way for us to use bulk inserts? Need this.

Thanks for your help.

SharadKumar avatar May 25 '16 14:05 SharadKumar

@myyellowshoe @nicooprat @SharadKumar

Way back in February I used the mikowals:batch-insert package to do batch insert. It worked (at least back then when I was using -v < 1.3), but I've since modified my database schema in favor of a more efficient structure that did not require batch inserting. It just wasn't performant, especially with Meteor. Just my own experience though.

Also ran into a huge bottleneck with doing schema validation on large database operations, which makes sense. I had to selectively skip validation for a few operations which obviously is not ideal. So it's important to recognize the advantages and disadvantages of no-sql when doing this sort of stuff.

beeekind avatar May 25 '16 19:05 beeekind

It's only in the NodeJS driver: https://mongodb.github.io/node-mongodb-native/api-generated/collection.html#insert

But not supported by Collection / Collection2: https://docs.meteor.com/api/collections.html#Mongo-Collection-insert

export const Tags: any = new Mongo.Collection('tags');
export const TagsSchema = new SimpleSchema({
    name: {
      type: String,
      min: 3,
      max: 30
    }
  },
  {
    clean: {
      filter: true,
      autoConvert: true,
      removeEmptyStrings: true,
      trimStrings: true,
      getAutoValues: true,
      removeNullsFromArrays: true,
    }
  }
);
Tags.attachSchema(TagsSchema);

Tags.insert([ { name: 'yxc' }, { name: 'cvb' } ], {bypassCollection2: true});

It always puts them into one document:

{ "_id" : "tT9KxRZa2zvQEsp6u", "0" : { "name" : "yxc" }, "1" : { "name" : "cvb" } }

Alternatives here: https://docs.meteor.com/api/collections.html#Mongo-Collection-insert

arichter83 avatar Jan 15 '19 13:01 arichter83