diff --git a/lib/persistence.js b/lib/persistence.js index 147f65f..4f28f9d 100644 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -217,6 +217,8 @@ Persistence.treatRawData = function (rawData) { } } else if (doc.$$indexCreated && doc.$$indexCreated.fieldName != undefined) { indexes[doc.$$indexCreated.fieldName] = doc.$$indexCreated; + } else if (typeof doc.$$indexRemoved === "string") { + delete indexes[doc.$$indexRemoved]; } } catch (e) { } diff --git a/test/db.test.js b/test/db.test.js index 5667d17..a346b2a 100644 --- a/test/db.test.js +++ b/test/db.test.js @@ -1291,7 +1291,7 @@ describe('Database', function () { describe('Using indexes', function () { - describe('ensureIndex and index initialization in database loading', function () { + describe.only('ensureIndex and index initialization in database loading', function () { it('ensureIndex can be called right after a loadDatabase and be initialized and filled correctly', function (done) { var now = new Date() @@ -1523,9 +1523,27 @@ describe('Database', function () { }); }); }); + + it('Can remove an index', function (done) { + d.ensureIndex({ fieldName: 'e' }, function (err) { + assert.isNull(err); + + Object.keys(d.indexes).length.should.equal(2); + assert.isNotNull(d.indexes.e); + + d.removeIndex("e", function (err) { + assert.isNull(err); + Object.keys(d.indexes).length.should.equal(1); + assert.isUndefined(d.indexes.e); + + done(); + }); + }); + }); }); // ==== End of 'ensureIndex and index initialization in database loading' ==== // + describe('Indexing newly inserted documents', function () { it('Newly inserted documents are indexed', function (done) { @@ -2006,10 +2024,10 @@ describe('Database', function () { }); }); - }); // ==== End of 'Removing indexes upon document update' ==== // + }); // ==== End of 'Updating indexes upon document remove' ==== // - describe.only('Persisting indexes', function () { + describe.skip('Persisting indexes', function () { it('Indexes are persisted to a separate file and recreated upon reload', function (done) { var persDb = "workspace/persistIndexes.db"