weasel

Mongoose add-on for saving bulk documents

npm install weasel
1 downloads in the last month

Weasel

Weasel is a small module written in coffee-script for allowing a developer to send an array of Mongoose documents and perform a bulk save.

Native JavaScript versions are non-coffee users are also available.

Installation/Usage

Include Weasel into your project

weasel = require './lib/weasel'

Create a normal schema as you would in Mongoose

# Connect to MongoDB
mongoose.connect "mongodb://localhost/demo"

# Create an example schema
Schema = mongoose.Schema

AnimalModel = new Schema({
    type: String
})

AnimalModel = mongoose.model 'animals', AnimalModel

Create an array of documents for Weasel

docs = []
animals = ['Monkeys','Elephants','Dogs', 'Horses']

animals.forEach (animal) ->
  doc = new AnimalModel
  doc.type = animal
  docs.push(doc)

Finally pass the array to Weasel:

weasel.saveAll docs, (results) ->
  console.log results + ' animals have been saved!'
npm loves you