Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 23, 2011 17:11
Show Gist options
  • Select an option

  • Save aheckmann/1237913 to your computer and use it in GitHub Desktop.

Select an option

Save aheckmann/1237913 to your computer and use it in GitHub Desktop.

Revisions

  1. aheckmann created this gist Sep 23, 2011.
    48 changes: 48 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@

    var mongoose = require('mongoose');
    mongoose.connect('localhost', 'testing_535');
    console.error('mongoose version', mongoose.version);

    var OID = mongoose.Types.ObjectId;

    var ASchema = new mongoose.Schema({
    square: mongoose.Schema.ObjectId
    , task: Number
    });

    var A = mongoose.model('A', ASchema);

    mongoose.connection.on('open', function () {
    var id = new OID;
    A.create(
    { square: id, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }
    , { square: new OID, task: 1 }, function (err) {
    if (err) return console.error(err.stack||err);
    A.find({}, function (err, docs) {
    if (err) return console.error(err.stack||err);
    console.error(docs);
    console.error('next');
    var ids = id.toString();
    A.find({ square: ids }, function (err, docs) {
    if (err) return console.error(err.stack||err);
    console.error('found by id');
    console.error(docs);
    mongoose.connection.db.dropDatabase(function () {
    mongoose.connection.close();
    });
    });
    });
    })
    });