From 362e5d4d15831516aa9bf2077f87d82469aa7e97 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Tue, 19 Jan 2016 11:03:31 +0100 Subject: [PATCH] TTL indexes ignore documents where indexed field not a date --- test/db.test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/db.test.js b/test/db.test.js index d467d20..697e6d9 100755 --- a/test/db.test.js +++ b/test/db.test.js @@ -598,6 +598,36 @@ describe('Database', function () { }); }); + it("Document where indexed field is absent or not a date are ignored", function (done) { + d.ensureIndex({ fieldName: 'exp', expireAfterSeconds: 0.2 }, function () { + d.insert({ hello: 'world1', exp: new Date() }, function () { + d.insert({ hello: 'world2', exp: "not a date" }, function () { + d.insert({ hello: 'world3' }, function () { + setTimeout(function () { + d.find({}, function (err, docs) { + assert.isNull(err); + docs.length.should.equal(3); + + setTimeout(function () { + d.find({}, function (err, docs) { + assert.isNull(err); + docs.length.should.equal(2); + + + docs[0].hello.should.not.equal('world1'); + docs[1].hello.should.not.equal('world1'); + + done(); + }); + }, 101); + }); + }, 100); + }); + }); + }); + }); + }); + }); // ==== End of '#getCandidates' ==== //