Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created August 13, 2012 17:50
Show Gist options
  • Save aheckmann/3342735 to your computer and use it in GitHub Desktop.
Save aheckmann/3342735 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var assert = require('assert')
console.log('\n===========');
console.log(' mongoose version: %s', mongoose.version);
console.log('========\n\n');
mongoose.connect('localhost', 'testing_allquery');
mongoose.connection.on('error', function () {
console.error('connection error', arguments);
});
var schema = new Schema({
name: { nested: [String] }
});
var A = mongoose.model('A', schema);
mongoose.set('debug', true)
mongoose.connection.on('open', function () {
var a = new A({ name: { nested: ['one','two','three'] }});
a.save(function (err, a) {
if (err) return done(err);
A.where('name.nested').all([/two/]).exec(function (err, docs) {
console.error('found', docs);
done(err);
});
})
});
function done (err) {
if (err) console.error(err.stack);
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment