public
Created

  • Download Gist
mongoose-query-by-date.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
mongoose.connect('localhost', 'testing_querybydate');
 
var schema = new Schema({
created: Date
, data: {}
});
 
var A = mongoose.model('A', schema);
 
mongoose.connection.on('open', function () {
var a = new A({ created: new Date });
a.save(function (err, a) {
if (err) return console.error(err.stack||err);
 
A.find({ created: { $lte: new Date('2012-05-16T20:54:35.630Z') }}, function (err, docs) {
if (err) console.error(err.stack||err);
console.error('found', docs);
 
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
});
})
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.