/batch-insert

meteor package using mongo batch inserts to avoid multiple database calls

Primary LanguageJavaScriptMIT LicenseMIT

NOTE: Temporary package

Created because mikowals:batch-insert incompatible version constraint with Meteor 1.7. If it's ever updated, use that instead. Given usage, probably better to replace with native mongo driver insertMany + simple write fence.

##If you find this package useful consider commenting on the meteor/meteor#1255 to get bulk insert support directly in Meteor core.

#batch-insert

Meteor package enabling mongo driver insert of multiple documents.

#Installation

In your meteor app directory run:

meteor add hiveteams:batch-insert

#Usage

The package creates a batchInsert() function on each collection instance. It is designed to work just like insert() but takes an array of objects to be inserted rather than a single object.

// on server and client
Data = new Meteor.Collection('data');

// must have an allow function on server to use batchInsert() on client.
Data.allow({
  insert: function(){ return true };
});

// on server or client
var newIds = Data.batchInsert([{item: junk},{item: garbage}]);  // returns array of created _id values

// use asynchronously on client or server.  
// On client it also synchronously returns _ids just like Mongo.Collection.insert().
var moreIds = Data.batchInsert([{item: junk2},{item: garbage2}], function( err, res){
  //called with err or res where res is array of created _id values
});  

Client side security is managed with allow / deny rules on the collection. There is no security on batchInsert() done from the server.