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

Support for bulk inserts #214

Open
rootedsoftware opened this issue Apr 23, 2015 · 10 comments
Open

Support for bulk inserts #214

rootedsoftware opened this issue Apr 23, 2015 · 10 comments
Milestone

Comments

@rootedsoftware
Copy link

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
Copy link
Collaborator

aldeed commented Apr 24, 2015

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

@rootedsoftware
Copy link
Author

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

@aldeed
Copy link
Collaborator

aldeed commented Apr 28, 2015

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

@aldeed
Copy link
Collaborator

aldeed commented Apr 29, 2015

@c316 see meteor/meteor#1255 (comment)

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

@beeekind
Copy link

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
Copy link

Agreed. Running into the same issue.

@nicooprat
Copy link

+1 on this one :)

@SharadKumar
Copy link

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

Thanks for your help.

@beeekind
Copy link

beeekind commented May 25, 2016

@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
Copy link

arichter83 commented Jan 15, 2019

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

@StorytellerCZ StorytellerCZ added this to the v4 milestone Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants