Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 23, 2011 17:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aheckmann/1237913 to your computer and use it in GitHub Desktop.
Save aheckmann/1237913 to your computer and use it in GitHub Desktop.
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();
});
});
});
})
});
@shebbys
Copy link

shebbys commented Sep 23, 2011

When I execute this I get the options logged:

A.find({ square: 'hi' }, function (err, docs) { console.log(docs); });
{ options: { populate: {} },
safe: undefined,
_conditions: {},
op: 'find',
model: { [Function: model] modelName: 'A' } }
[]
A.find({ }, function (err, docs) { console.log(docs); });
{ options: { populate: {} },
safe: undefined,
_conditions: {},
op: 'find',
model: { [Function: model] modelName: 'A' } }
[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment