Skip to content

Instantly share code, notes, and snippets.

@colwilson
Created October 19, 2011 13:07
Show Gist options
  • Save colwilson/1298226 to your computer and use it in GitHub Desktop.
Save colwilson/1298226 to your computer and use it in GitHub Desktop.
# import mongoose
mongoose = require('mongoose')
# connect
db = mongoose.connect('mongodb://localhost/test')
# define the schema
basketSchema = new mongoose.Schema
fruit: String
count: Number
# define model from the schema
Basket = mongoose.model "basket", basketSchema
# define some dummy data
baskets = [{
fruit: 'apple'
count: 27
},{
fruit: 'apple'
count: 32
},{
fruit: 'pear'
count: 26
},{
fruit: 'orange'
count: 16
}]
# load dummy data into mongodb
for basket in baskets
b = new Basket basket
b.save (err) ->
if err
console.log err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment