Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

Support for bulk inserts #214

Open rootedsoftware opened 9 years ago

rootedsoftware commented 9 years ago

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.

aldeed commented 9 years ago

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

rootedsoftware commented 9 years ago

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

aldeed commented 9 years ago

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

aldeed commented 9 years ago

@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.

beeekind commented 8 years ago

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.

myyellowshoe commented 8 years ago

Agreed. Running into the same issue.

nicooprat commented 8 years ago

+1 on this one :)

SharadKumar commented 8 years ago

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

Thanks for your help.

beeekind commented 8 years ago

@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.

arichter83 commented 5 years ago

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