Still some problems to solve with indexing

pull/2/head
Louis Chatriot 12 years ago
parent 5b62825e8f
commit 08804dde82
  1. 8
      lib/datastore.js
  2. 66
      test/db.test.js

@ -419,13 +419,17 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
}); });
} }
, function () { // Perform the update , function () { // Perform the update
candidates = self.getCandidates(query) var modified;
candidates = self.getCandidates(query);
try { try {
for (i = 0; i < candidates.length; i += 1) { for (i = 0; i < candidates.length; i += 1) {
if (model.match(candidates[i], query) && (multi || numReplaced === 0)) { if (model.match(candidates[i], query) && (multi || numReplaced === 0)) {
numReplaced += 1; numReplaced += 1;
candidates[i] = model.modify(candidates[i], updateQuery); modified = model.modify(candidates[i], updateQuery);
self.updateIndexes(candidates[i], modified);
candidates[i] = modified;
updatedDocs.push(candidates[i]); updatedDocs.push(candidates[i]);
} }
} }

@ -1416,8 +1416,74 @@ describe('Database', function () {
}); });
}); });
it.skip('Insertion still works as before with indexing', function (done) {
d.ensureIndex({ fieldName: 'a' });
d.ensureIndex({ fieldName: 'b' });
d.insert({ a: 1, b: 'hello' }, function (err, doc1) {
d.insert({ a: 2, b: 'si' }, function (err, doc2) {
d.find({}, function (err, docs) {
console.log(d.data);
// TODO
done();
});
});
});
});
}); // ==== End of 'Indexing newly inserted documents' ==== // }); // ==== End of 'Indexing newly inserted documents' ==== //
describe('Updating indexes upon document update', function () {
it.skip('Indexes get updated when a document (or multiple documents) is updated', function (done) {
d.ensureIndex({ fieldName: 'a' });
d.ensureIndex({ fieldName: 'b' });
d.insert({ a: 1, b: 'hello' }, function (err, doc1) {
d.insert({ a: 2, b: 'si' }, function (err, doc2) {
d.update({ a: 1 }, { $set: { a: 456, b: 'no' } }, {}, function (err, nr) {
assert.isNull(err);
nr.should.equal(1);
console.log(d.data);
throw 'fds'; // TODO
d.indexes.a.tree.getNumberOfKeys().should.equal(2);
d.indexes.a.getMatching(456)[0]._id.should.equal(doc1._id);
d.indexes.a.getMatching(2)[0]._id.should.equal(doc2._id);
d.indexes.b.tree.getNumberOfKeys().should.equal(2);
d.indexes.b.getMatching('no')[0]._id.should.equal(doc1._id);
d.indexes.b.getMatching('si')[0]._id.should.equal(doc2._id);
console.log("========================");
console.log("========================");
d.update({}, { $inc: { a: 10 }, $set: { b: 'same' } }, { multi: true }, function () {
assert.isNull(err);
nr.should.equal(2);
d.indexes.a.tree.getNumberOfKeys().should.equal(2);
d.indexes.a.getMatching(466)[0]._id.should.equal(doc1._id);
d.indexes.a.getMatching(12)[0]._id.should.equal(doc2._id);
d.indexes.b.tree.getNumberOfKeys().should.equal(1);
d.indexes.b.getMatching('same')[0]._id.should.equal(doc1._id);
d.indexes.b.getMatching('same')[1]._id.should.equal(doc2._id);
done();
});
});
});
});
});
it.skip('If an update violates a contraints, nothing is done', function (done) {
});
it.skip('Updates still work with indexing', function (done) {
});
}); // ==== End of 'Updating indexes upon document update' ==== //

Loading…
Cancel
Save