2 var mongoose = require('../../lib');
3 var Schema = mongoose.Schema;
5 console.log('Running mongoose version %s', mongoose.version);
11 var consoleSchema = Schema({
16 var Console = mongoose.model('Console', consoleSchema);
22 var gameSchema = Schema({
27 type: Schema.Types.ObjectId,
31 var Game = mongoose.model('Game', gameSchema);
34 * Connect to the console database on localhost with
35 * the default port (27017)
38 mongoose.connect('mongodb://localhost/console', function(err) {
39 // if we failed to connect, abort
50 function createData() {
54 manufacturer: 'Nintendo',
55 released: 'September 29, 1996'
57 function(err, nintendo64) {
58 if (err) return done(err);
61 name: 'Legend of Zelda: Ocarina of Time',
62 developer: 'Nintendo',
63 released: new Date('November 21, 1998'),
64 consoles: [nintendo64]
67 if (err) return done(err);
80 .findOne({name: /^Legend of Zelda/})
81 .exec(function(err, ocinara) {
82 if (err) return done(err);
84 console.log('"%s" console _id: %s', ocinara.name, ocinara.consoles[0]);
86 // population of existing document
87 ocinara.populate('consoles', function(err) {
88 if (err) return done(err);
91 '"%s" was released for the %s on %s',
93 ocinara.consoles[0].name,
94 ocinara.released.toLocaleDateString()
103 if (err) console.error(err);
104 Console.remove(function() {
105 Game.remove(function() {
106 mongoose.disconnect();