inserts = () -> mongoose.connect 'mongodb://localhost/article' chapters = mongoose.model 'chapters', chapters Articles = mongoose.model 'Articles', Articles instance = new chapters() instance.order = 123 article = new Articles() article.identity = 1 article.full_title = "Wind in the Willows" instance.articles.push article article = new Articles() article.identity = 2 article.full_title = "Sleepy Hollow" instance.articles.push article instance.save (err) -> if err? console.log "Errors saving with #{ err }" inserts() retrieve = () -> mongoose.connect 'mongodb://localhost/article' myModel = mongoose.model 'chapters', chapters myModel.find {}, (err, docs) -> all_chaps = new ChapterCollection() all_chaps.mport docs, {silent: true} console.log "MPORTed backbone: #{ JSON.stringify all_chaps }" console.log "XPORTed backbone: #{ JSON.stringify all_chaps.xport() }" retrieve() simple = () -> chapter = new ChapterB {name: 'Tres', order: 123 } coll = new ChapterCollection [chapter] chapter = new ChapterB {name: 'ada', order: 123 } coll.add chapter top = new ChapterTop() top.chapters.add chapter console.log "xport of basic object from hand #{ JSON.stringify top.xport() }" console.log "print of basic object from hand #{ JSON.stringify top.print() }" simple()