Skip to content

Instantly share code, notes, and snippets.

@rgarcia
Created April 30, 2012 21:33
Show Gist options
  • Save rgarcia/2562852 to your computer and use it in GitHub Desktop.
Save rgarcia/2562852 to your computer and use it in GitHub Desktop.
weird mongoose behavior
step = require 'step'
mongoose = require 'mongoose'
Schema = mongoose.Schema
schemas = {}
schemas.Foobar = new Schema
name : { type: String, trim: true, required: true, unique: true }
connection = mongoose.createConnection 'mongodb://127.0.0.1:27017/sandbox'
models = {}
models.Foobar = connection.model 'Foobar', schemas.Foobar
foobar = new models.Foobar
name: 'FOOOOO'
step () ->
models.Foobar.find {}, this
, (err, docs) ->
console.log 'found docs', docs
console.log 'disconnecting'
mongoose.disconnect this
, (err) ->
throw err if err
console.log 'disconnected'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment