https://github.com/mikowals/batch-insert
Meteor package enabling batch document inserts to reduce database traffic.
https://github.com/mikowals/batch-insert
meteor mongodb nodejs optimistic-ui
Last synced: 6 days ago
JSON representation
Meteor package enabling batch document inserts to reduce database traffic.
- Host: GitHub
- URL: https://github.com/mikowals/batch-insert
- Owner: mikowals
- License: mit
- Created: 2014-12-28T04:45:45.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T05:35:08.000Z (almost 3 years ago)
- Last Synced: 2024-04-09T14:40:56.244Z (over 1 year ago)
- Topics: meteor, mongodb, nodejs, optimistic-ui
- Language: JavaScript
- Homepage:
- Size: 188 KB
- Stars: 40
- Watchers: 6
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# batch-insert
Meteor package enabling insert of multiple documents while maintaining reactivity and respecting `allow` and `deny` rules.
If you find this package useful consider commenting at https://github.com/meteor/meteor-feature-requests/issues/15 to get bulk insert support directly in Meteor core.
# Installation
In your meteor app directory run:
meteor add mikowals:batch-insert
# Usage
The package adds a `batchInsert()` function on each collection instance. It works just like `insert()` but takes an array of objects and returns an array of `_id`s.
On the client, the `_id`s are available synchronously. Client-side security is managed with allow / deny rules on the collection.
On the server, inserted documents are published to subscribed clients when the `batchInsert` completes successfully.
// 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.
var moreIds = Data.batchInsert([{item: junk2},{item: garbage2}], function( err, res){
//called with err or res where res is array of created _id values
});