|
|
@ -3,7 +3,6 @@ const chai = require('chai') |
|
|
|
const testDb = 'workspace/test.db' |
|
|
|
const testDb = 'workspace/test.db' |
|
|
|
const fs = require('fs') |
|
|
|
const fs = require('fs') |
|
|
|
const path = require('path') |
|
|
|
const path = require('path') |
|
|
|
const _ = require('underscore') |
|
|
|
|
|
|
|
const async = require('async') |
|
|
|
const async = require('async') |
|
|
|
const model = require('../lib/model') |
|
|
|
const model = require('../lib/model') |
|
|
|
const Datastore = require('../lib/datastore') |
|
|
|
const Datastore = require('../lib/datastore') |
|
|
@ -147,9 +146,9 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
_.pluck(docs, 'somedata').should.contain('ok') |
|
|
|
docs.map(x => x.somedata).should.contain('ok') |
|
|
|
_.pluck(docs, 'somedata').should.contain('another') |
|
|
|
docs.map(x => x.somedata).should.contain('another') |
|
|
|
_.pluck(docs, 'somedata').should.contain('again') |
|
|
|
docs.map(x => x.somedata).should.contain('again') |
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -249,11 +248,11 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.find(docs, function (doc) { return doc.a === 5 }).b.should.equal('hello') |
|
|
|
docs.find(function (doc) { return doc.a === 5 }).b.should.equal('hello') |
|
|
|
_.find(docs, function (doc) { return doc.a === 42 }).b.should.equal('world') |
|
|
|
docs.find(function (doc) { return doc.a === 42 }).b.should.equal('world') |
|
|
|
|
|
|
|
|
|
|
|
// The data has been persisted correctly
|
|
|
|
// The data has been persisted correctly
|
|
|
|
const data = _.filter(fs.readFileSync(testDb, 'utf8').split('\n'), function (line) { return line.length > 0 }) |
|
|
|
const data = fs.readFileSync(testDb, 'utf8').split('\n').filter(function (line) { return line.length > 0 }) |
|
|
|
data.length.should.equal(2) |
|
|
|
data.length.should.equal(2) |
|
|
|
model.deserialize(data[0]).a.should.equal(5) |
|
|
|
model.deserialize(data[0]).a.should.equal(5) |
|
|
|
model.deserialize(data[0]).b.should.equal('hello') |
|
|
|
model.deserialize(data[0]).b.should.equal('hello') |
|
|
@ -276,7 +275,7 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
// Datafile only contains index definition
|
|
|
|
// Datafile only contains index definition
|
|
|
|
const datafileContents = model.deserialize(fs.readFileSync(testDb, 'utf8')) |
|
|
|
const datafileContents = model.deserialize(fs.readFileSync(testDb, 'utf8')) |
|
|
|
assert.deepEqual(datafileContents, { $$indexCreated: { fieldName: 'a', unique: true } }) |
|
|
|
assert.deepStrictEqual(datafileContents, { $$indexCreated: { fieldName: 'a', unique: true } }) |
|
|
|
|
|
|
|
|
|
|
|
docs.length.should.equal(0) |
|
|
|
docs.length.should.equal(0) |
|
|
|
|
|
|
|
|
|
|
@ -296,7 +295,7 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert(newDoc, function (err, insertedDoc) { |
|
|
|
d.insert(newDoc, function (err, insertedDoc) { |
|
|
|
// No side effect on given input
|
|
|
|
// No side effect on given input
|
|
|
|
assert.deepEqual(newDoc, { hello: 'world' }) |
|
|
|
assert.deepStrictEqual(newDoc, { hello: 'world' }) |
|
|
|
// Insert doc has two new fields, _id and createdAt
|
|
|
|
// Insert doc has two new fields, _id and createdAt
|
|
|
|
insertedDoc.hello.should.equal('world') |
|
|
|
insertedDoc.hello.should.equal('world') |
|
|
|
assert.isDefined(insertedDoc.createdAt) |
|
|
|
assert.isDefined(insertedDoc.createdAt) |
|
|
@ -313,8 +312,8 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.length.should.equal(1) |
|
|
|
docs.length.should.equal(1) |
|
|
|
assert.deepEqual(newDoc, { hello: 'world' }) |
|
|
|
assert.deepStrictEqual(newDoc, { hello: 'world' }) |
|
|
|
assert.deepEqual({ |
|
|
|
assert.deepStrictEqual({ |
|
|
|
hello: 'world', |
|
|
|
hello: 'world', |
|
|
|
_id: insertedDoc._id, |
|
|
|
_id: insertedDoc._id, |
|
|
|
createdAt: insertedDoc.createdAt, |
|
|
|
createdAt: insertedDoc.createdAt, |
|
|
@ -326,8 +325,8 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.length.should.equal(1) |
|
|
|
docs.length.should.equal(1) |
|
|
|
assert.deepEqual(newDoc, { hello: 'world' }) |
|
|
|
assert.deepStrictEqual(newDoc, { hello: 'world' }) |
|
|
|
assert.deepEqual({ |
|
|
|
assert.deepStrictEqual({ |
|
|
|
hello: 'world', |
|
|
|
hello: 'world', |
|
|
|
_id: insertedDoc._id, |
|
|
|
_id: insertedDoc._id, |
|
|
|
createdAt: insertedDoc.createdAt, |
|
|
|
createdAt: insertedDoc.createdAt, |
|
|
@ -352,7 +351,7 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.length.should.equal(1) |
|
|
|
docs.length.should.equal(1) |
|
|
|
assert.deepEqual(docs[0], insertedDoc) |
|
|
|
assert.deepStrictEqual(docs[0], insertedDoc) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -370,12 +369,12 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(insertedDoc, docs[0]) |
|
|
|
assert.deepStrictEqual(insertedDoc, docs[0]) |
|
|
|
|
|
|
|
|
|
|
|
d.loadDatabase(function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(insertedDoc, docs[0]) |
|
|
|
assert.deepStrictEqual(insertedDoc, docs[0]) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -395,12 +394,12 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(insertedDoc, docs[0]) |
|
|
|
assert.deepStrictEqual(insertedDoc, docs[0]) |
|
|
|
|
|
|
|
|
|
|
|
d.loadDatabase(function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(insertedDoc, docs[0]) |
|
|
|
assert.deepStrictEqual(insertedDoc, docs[0]) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -473,12 +472,12 @@ describe('Database', function () { |
|
|
|
d.insert({ tf: 9 }, function () { |
|
|
|
d.insert({ tf: 9 }, function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.getCandidates({ r: 6, tf: 4 }, function (err, data) { |
|
|
|
d.getCandidates({ r: 6, tf: 4 }, function (err, data) { |
|
|
|
const doc1 = _.find(data, function (d) { return d._id === _doc1._id }) |
|
|
|
const doc1 = data.find(function (d) { return d._id === _doc1._id }) |
|
|
|
const doc2 = _.find(data, function (d) { return d._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (d) { return d._id === _doc2._id }) |
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2) |
|
|
|
data.length.should.equal(2) |
|
|
|
assert.deepEqual(doc1, { _id: doc1._id, tf: 4 }) |
|
|
|
assert.deepStrictEqual(doc1, { _id: doc1._id, tf: 4 }) |
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, tf: 4, an: 'other' }) |
|
|
|
assert.deepStrictEqual(doc2, { _id: doc2._id, tf: 4, an: 'other' }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -502,12 +501,12 @@ describe('Database', function () { |
|
|
|
d.insert({ tf: 9 }, function (err, _doc2) { |
|
|
|
d.insert({ tf: 9 }, function (err, _doc2) { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.getCandidates({ r: 6, tf: { $in: [6, 9, 5] } }, function (err, data) { |
|
|
|
d.getCandidates({ r: 6, tf: { $in: [6, 9, 5] } }, function (err, data) { |
|
|
|
const doc1 = _.find(data, function (d) { return d._id === _doc1._id }) |
|
|
|
const doc1 = data.find(function (d) { return d._id === _doc1._id }) |
|
|
|
const doc2 = _.find(data, function (d) { return d._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (d) { return d._id === _doc2._id }) |
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2) |
|
|
|
data.length.should.equal(2) |
|
|
|
assert.deepEqual(doc1, { _id: doc1._id, tf: 6 }) |
|
|
|
assert.deepStrictEqual(doc1, { _id: doc1._id, tf: 6 }) |
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, tf: 9 }) |
|
|
|
assert.deepStrictEqual(doc2, { _id: doc2._id, tf: 9 }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -531,16 +530,16 @@ describe('Database', function () { |
|
|
|
d.insert({ tf: 9 }, function (err, _doc4) { |
|
|
|
d.insert({ tf: 9 }, function (err, _doc4) { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.getCandidates({ r: 6, notf: { $in: [6, 9, 5] } }, function (err, data) { |
|
|
|
d.getCandidates({ r: 6, notf: { $in: [6, 9, 5] } }, function (err, data) { |
|
|
|
const doc1 = _.find(data, function (d) { return d._id === _doc1._id }) |
|
|
|
const doc1 = data.find(function (d) { return d._id === _doc1._id }) |
|
|
|
const doc2 = _.find(data, function (d) { return d._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (d) { return d._id === _doc2._id }) |
|
|
|
const doc3 = _.find(data, function (d) { return d._id === _doc3._id }) |
|
|
|
const doc3 = data.find(function (d) { return d._id === _doc3._id }) |
|
|
|
const doc4 = _.find(data, function (d) { return d._id === _doc4._id }) |
|
|
|
const doc4 = data.find(function (d) { return d._id === _doc4._id }) |
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(4) |
|
|
|
data.length.should.equal(4) |
|
|
|
assert.deepEqual(doc1, { _id: doc1._id, tf: 4 }) |
|
|
|
assert.deepStrictEqual(doc1, { _id: doc1._id, tf: 4 }) |
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, tf: 6 }) |
|
|
|
assert.deepStrictEqual(doc2, { _id: doc2._id, tf: 6 }) |
|
|
|
assert.deepEqual(doc3, { _id: doc3._id, tf: 4, an: 'other' }) |
|
|
|
assert.deepStrictEqual(doc3, { _id: doc3._id, tf: 4, an: 'other' }) |
|
|
|
assert.deepEqual(doc4, { _id: doc4._id, tf: 9 }) |
|
|
|
assert.deepStrictEqual(doc4, { _id: doc4._id, tf: 9 }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -564,12 +563,12 @@ describe('Database', function () { |
|
|
|
d.insert({ tf: 9 }, function (err, _doc4) { |
|
|
|
d.insert({ tf: 9 }, function (err, _doc4) { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.getCandidates({ r: 6, tf: { $lte: 9, $gte: 6 } }, function (err, data) { |
|
|
|
d.getCandidates({ r: 6, tf: { $lte: 9, $gte: 6 } }, function (err, data) { |
|
|
|
const doc2 = _.find(data, function (d) { return d._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (d) { return d._id === _doc2._id }) |
|
|
|
const doc4 = _.find(data, function (d) { return d._id === _doc4._id }) |
|
|
|
const doc4 = data.find(function (d) { return d._id === _doc4._id }) |
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2) |
|
|
|
data.length.should.equal(2) |
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, tf: 6 }) |
|
|
|
assert.deepStrictEqual(doc2, { _id: doc2._id, tf: 6 }) |
|
|
|
assert.deepEqual(doc4, { _id: doc4._id, tf: 9 }) |
|
|
|
assert.deepStrictEqual(doc4, { _id: doc4._id, tf: 9 }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -698,10 +697,10 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
_.pluck(docs, 'somedata').should.contain('ok') |
|
|
|
docs.map(x => x.somedata).should.contain('ok') |
|
|
|
_.pluck(docs, 'somedata').should.contain('another') |
|
|
|
docs.map(x => x.somedata).should.contain('another') |
|
|
|
_.find(docs, function (d) { return d.somedata === 'another' }).plus.should.equal('additional data') |
|
|
|
docs.find(function (d) { return d.somedata === 'another' }).plus.should.equal('additional data') |
|
|
|
_.pluck(docs, 'somedata').should.contain('again') |
|
|
|
docs.map(x => x.somedata).should.contain('again') |
|
|
|
return cb() |
|
|
|
return cb() |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -723,7 +722,7 @@ describe('Database', function () { |
|
|
|
d.find({ somedata: 'again' }, function (err, docs) { |
|
|
|
d.find({ somedata: 'again' }, function (err, docs) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.pluck(docs, 'somedata').should.not.contain('ok') |
|
|
|
docs.map(x => x.somedata).should.not.contain('ok') |
|
|
|
return cb() |
|
|
|
return cb() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
@ -827,14 +826,14 @@ describe('Database', function () { |
|
|
|
d.find({ fruits: 'pear' }, function (err, docs) { |
|
|
|
d.find({ fruits: 'pear' }, function (err, docs) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.pluck(docs, '_id').should.contain(doc1._id) |
|
|
|
docs.map(x => x._id).should.contain(doc1._id) |
|
|
|
_.pluck(docs, '_id').should.contain(doc2._id) |
|
|
|
docs.map(x => x._id).should.contain(doc2._id) |
|
|
|
|
|
|
|
|
|
|
|
d.find({ fruits: 'banana' }, function (err, docs) { |
|
|
|
d.find({ fruits: 'banana' }, function (err, docs) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.pluck(docs, '_id').should.contain(doc1._id) |
|
|
|
docs.map(x => x._id).should.contain(doc1._id) |
|
|
|
_.pluck(docs, '_id').should.contain(doc3._id) |
|
|
|
docs.map(x => x._id).should.contain(doc3._id) |
|
|
|
|
|
|
|
|
|
|
|
d.find({ fruits: 'doesntexist' }, function (err, docs) { |
|
|
|
d.find({ fruits: 'doesntexist' }, function (err, docs) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
@ -953,12 +952,12 @@ describe('Database', function () { |
|
|
|
d.find({ a: 2 }, { a: 0, _id: 0 }, function (err, docs) { |
|
|
|
d.find({ a: 2 }, { a: 0, _id: 0 }, function (err, docs) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
docs.length.should.equal(1) |
|
|
|
docs.length.should.equal(1) |
|
|
|
assert.deepEqual(docs[0], { hello: 'world' }) |
|
|
|
assert.deepStrictEqual(docs[0], { hello: 'world' }) |
|
|
|
|
|
|
|
|
|
|
|
d.find({ a: 2 }, { a: 0, _id: 0 }).exec(function (err, docs) { |
|
|
|
d.find({ a: 2 }, { a: 0, _id: 0 }).exec(function (err, docs) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
docs.length.should.equal(1) |
|
|
|
docs.length.should.equal(1) |
|
|
|
assert.deepEqual(docs[0], { hello: 'world' }) |
|
|
|
assert.deepStrictEqual(docs[0], { hello: 'world' }) |
|
|
|
|
|
|
|
|
|
|
|
// Can't use both modes at once if not _id
|
|
|
|
// Can't use both modes at once if not _id
|
|
|
|
d.find({ a: 2 }, { a: 0, hello: 1 }, function (err, docs) { |
|
|
|
d.find({ a: 2 }, { a: 0, hello: 1 }, function (err, docs) { |
|
|
@ -985,11 +984,11 @@ describe('Database', function () { |
|
|
|
d.insert({ a: 24, hello: 'earth' }, function (err, doc1) { |
|
|
|
d.insert({ a: 24, hello: 'earth' }, function (err, doc1) { |
|
|
|
d.findOne({ a: 2 }, { a: 0, _id: 0 }, function (err, doc) { |
|
|
|
d.findOne({ a: 2 }, { a: 0, _id: 0 }, function (err, doc) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
assert.deepEqual(doc, { hello: 'world' }) |
|
|
|
assert.deepStrictEqual(doc, { hello: 'world' }) |
|
|
|
|
|
|
|
|
|
|
|
d.findOne({ a: 2 }, { a: 0, _id: 0 }).exec(function (err, doc) { |
|
|
|
d.findOne({ a: 2 }, { a: 0, _id: 0 }).exec(function (err, doc) { |
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
assert.deepEqual(doc, { hello: 'world' }) |
|
|
|
assert.deepStrictEqual(doc, { hello: 'world' }) |
|
|
|
|
|
|
|
|
|
|
|
// Can't use both modes at once if not _id
|
|
|
|
// Can't use both modes at once if not _id
|
|
|
|
d.findOne({ a: 2 }, { a: 0, hello: 1 }, function (err, doc) { |
|
|
|
d.findOne({ a: 2 }, { a: 0, hello: 1 }, function (err, doc) { |
|
|
@ -1119,16 +1118,16 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
const doc1 = _.find(docs, function (d) { return d.somedata === 'ok' }) |
|
|
|
const doc1 = docs.find(function (d) { return d.somedata === 'ok' }) |
|
|
|
const doc2 = _.find(docs, function (d) { return d.somedata === 'again' }) |
|
|
|
const doc2 = docs.find(function (d) { return d.somedata === 'again' }) |
|
|
|
const doc3 = _.find(docs, function (d) { return d.somedata === 'another' }) |
|
|
|
const doc3 = docs.find(function (d) { return d.somedata === 'another' }) |
|
|
|
|
|
|
|
|
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
assert.isUndefined(_.find(docs, function (d) { return d.newDoc === 'yes' })) |
|
|
|
assert.isUndefined(docs.find(function (d) { return d.newDoc === 'yes' })) |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(doc1, { _id: doc1._id, somedata: 'ok' }) |
|
|
|
assert.deepStrictEqual(doc1, { _id: doc1._id, somedata: 'ok' }) |
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, somedata: 'again', plus: 'additional data' }) |
|
|
|
assert.deepStrictEqual(doc2, { _id: doc2._id, somedata: 'again', plus: 'additional data' }) |
|
|
|
assert.deepEqual(doc3, { _id: doc3._id, somedata: 'another' }) |
|
|
|
assert.deepStrictEqual(doc3, { _id: doc3._id, somedata: 'another' }) |
|
|
|
|
|
|
|
|
|
|
|
return cb() |
|
|
|
return cb() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1176,9 +1175,9 @@ describe('Database', function () { |
|
|
|
function testPostUpdateState (cb) { |
|
|
|
function testPostUpdateState (cb) { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
const doc1 = _.find(docs, function (d) { return d._id === id1 }) |
|
|
|
const doc1 = docs.find(function (d) { return d._id === id1 }) |
|
|
|
const doc2 = _.find(docs, function (d) { return d._id === id2 }) |
|
|
|
const doc2 = docs.find(function (d) { return d._id === id2 }) |
|
|
|
const doc3 = _.find(docs, function (d) { return d._id === id3 }) |
|
|
|
const doc3 = docs.find(function (d) { return d._id === id3 }) |
|
|
|
|
|
|
|
|
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
|
|
|
|
|
|
|
@ -1238,22 +1237,22 @@ describe('Database', function () { |
|
|
|
function testPostUpdateState (cb) { |
|
|
|
function testPostUpdateState (cb) { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
const doc1 = _.find(docs, function (d) { return d._id === id1 }) |
|
|
|
const doc1 = docs.find(function (d) { return d._id === id1 }) |
|
|
|
const doc2 = _.find(docs, function (d) { return d._id === id2 }) |
|
|
|
const doc2 = docs.find(function (d) { return d._id === id2 }) |
|
|
|
const doc3 = _.find(docs, function (d) { return d._id === id3 }) |
|
|
|
const doc3 = docs.find(function (d) { return d._id === id3 }) |
|
|
|
|
|
|
|
|
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(doc1, { somedata: 'ok', _id: doc1._id }) |
|
|
|
assert.deepStrictEqual(doc1, { somedata: 'ok', _id: doc1._id }) |
|
|
|
|
|
|
|
|
|
|
|
// doc2 or doc3 was modified. Since we sort on _id and it is random
|
|
|
|
// doc2 or doc3 was modified. Since we sort on _id and it is random
|
|
|
|
// it can be either of two situations
|
|
|
|
// it can be either of two situations
|
|
|
|
try { |
|
|
|
try { |
|
|
|
assert.deepEqual(doc2, { newDoc: 'yes', _id: doc2._id }) |
|
|
|
assert.deepStrictEqual(doc2, { newDoc: 'yes', _id: doc2._id }) |
|
|
|
assert.deepEqual(doc3, { somedata: 'again', _id: doc3._id }) |
|
|
|
assert.deepStrictEqual(doc3, { somedata: 'again', _id: doc3._id }) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
assert.deepEqual(doc2, { somedata: 'again', plus: 'additional data', _id: doc2._id }) |
|
|
|
assert.deepStrictEqual(doc2, { somedata: 'again', plus: 'additional data', _id: doc2._id }) |
|
|
|
assert.deepEqual(doc3, { newDoc: 'yes', _id: doc3._id }) |
|
|
|
assert.deepStrictEqual(doc3, { newDoc: 'yes', _id: doc3._id }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return cb() |
|
|
|
return cb() |
|
|
@ -1500,7 +1499,7 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(docs, [{ _id: newDoc._id, hello: 'world' }]) |
|
|
|
assert.deepStrictEqual(docs, [{ _id: newDoc._id, hello: 'world' }]) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1551,8 +1550,8 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.isEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }) |
|
|
|
_.isEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }) |
|
|
|
|
|
|
|
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
d.loadDatabase(function (err) { |
|
|
|
d.loadDatabase(function (err) { |
|
|
@ -1562,8 +1561,8 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.isEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }) |
|
|
|
_.isEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1588,9 +1587,9 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
_.isEqual(docs[0], { _id: doc1._id, a: 1, hello: 'changed' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc1._id, a: 1, hello: 'changed' }) |
|
|
|
_.isEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }) |
|
|
|
_.isEqual(docs[2], { _id: doc3._id, a: 5, hello: 'pluton' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[2], { _id: doc3._id, a: 5, hello: 'pluton' }) |
|
|
|
|
|
|
|
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
d.loadDatabase(function (err) { |
|
|
|
d.loadDatabase(function (err) { |
|
|
@ -1600,9 +1599,9 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
_.isEqual(docs[0], { _id: doc1._id, a: 1, hello: 'changed' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc1._id, a: 1, hello: 'changed' }) |
|
|
|
_.isEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[1], { _id: doc2._id, a: 2, hello: 'changed' }) |
|
|
|
_.isEqual(docs[2], { _id: doc3._id, a: 5, hello: 'pluton' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[2], { _id: doc3._id, a: 5, hello: 'pluton' }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1626,9 +1625,9 @@ describe('Database', function () { |
|
|
|
nr.should.equal(1) |
|
|
|
nr.should.equal(1) |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
const d1 = _.find(docs, function (doc) { return doc._id === doc1._id }) |
|
|
|
const d1 = docs.find(function (doc) { return doc._id === doc1._id }) |
|
|
|
const d2 = _.find(docs, function (doc) { return doc._id === doc2._id }) |
|
|
|
const d2 = docs.find(function (doc) { return doc._id === doc2._id }) |
|
|
|
const d3 = _.find(docs, function (doc) { return doc._id === doc3._id }) |
|
|
|
const d3 = docs.find(function (doc) { return doc._id === doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
d1.a.should.equal(1) |
|
|
|
d1.a.should.equal(1) |
|
|
|
d2.a.should.equal(12) |
|
|
|
d2.a.should.equal(12) |
|
|
@ -1655,18 +1654,20 @@ describe('Database', function () { |
|
|
|
assert.isDefined(err) |
|
|
|
assert.isDefined(err) |
|
|
|
|
|
|
|
|
|
|
|
// No index modified
|
|
|
|
// No index modified
|
|
|
|
_.each(d.indexes, function (index) { |
|
|
|
for (const key in d.indexes) { |
|
|
|
const docs = index.getAll() |
|
|
|
if (Object.prototype.hasOwnProperty.call(d.indexes, key)) { |
|
|
|
const d1 = _.find(docs, function (doc) { return doc._id === doc1._id }) |
|
|
|
const index = d.indexes[key] |
|
|
|
const d2 = _.find(docs, function (doc) { return doc._id === doc2._id }) |
|
|
|
const docs = index.getAll() |
|
|
|
const d3 = _.find(docs, function (doc) { return doc._id === doc3._id }) |
|
|
|
const d1 = docs.find(function (doc) { return doc._id === doc1._id }) |
|
|
|
|
|
|
|
const d2 = docs.find(function (doc) { return doc._id === doc2._id }) |
|
|
|
// All changes rolled back, including those that didn't trigger an error
|
|
|
|
const d3 = docs.find(function (doc) { return doc._id === doc3._id }) |
|
|
|
d1.a.should.equal(4) |
|
|
|
|
|
|
|
d2.a.should.equal(5) |
|
|
|
// All changes rolled back, including those that didn't trigger an error
|
|
|
|
d3.a.should.equal('abc') |
|
|
|
d1.a.should.equal(4) |
|
|
|
}) |
|
|
|
d2.a.should.equal(5) |
|
|
|
|
|
|
|
d3.a.should.equal('abc') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1685,15 +1686,17 @@ describe('Database', function () { |
|
|
|
assert.isDefined(err) |
|
|
|
assert.isDefined(err) |
|
|
|
|
|
|
|
|
|
|
|
// Check that no index was modified
|
|
|
|
// Check that no index was modified
|
|
|
|
_.each(d.indexes, function (index) { |
|
|
|
for (const key in d.indexes) { |
|
|
|
const docs = index.getAll() |
|
|
|
if (Object.prototype.hasOwnProperty.call(d.indexes, key)) { |
|
|
|
const d1 = _.find(docs, function (doc) { return doc._id === doc1._id }) |
|
|
|
const index = d.indexes[key] |
|
|
|
const d2 = _.find(docs, function (doc) { return doc._id === doc2._id }) |
|
|
|
const docs = index.getAll() |
|
|
|
|
|
|
|
const d1 = docs.find(function (doc) { return doc._id === doc1._id }) |
|
|
|
d1.a.should.equal(4) |
|
|
|
const d2 = docs.find(function (doc) { return doc._id === doc2._id }) |
|
|
|
d2.a.should.equal(5) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d1.a.should.equal(4) |
|
|
|
|
|
|
|
d2.a.should.equal(5) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1960,8 +1963,8 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.isEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }) |
|
|
|
_.isEqual(docs[1], { _id: doc3._id, a: 3, hello: 'moto' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[1], { _id: doc3._id, a: 3, hello: 'moto' }) |
|
|
|
|
|
|
|
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
d.loadDatabase(function (err) { |
|
|
|
d.loadDatabase(function (err) { |
|
|
@ -1971,8 +1974,8 @@ describe('Database', function () { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.sort(function (a, b) { return a.a - b.a }) |
|
|
|
docs.length.should.equal(2) |
|
|
|
docs.length.should.equal(2) |
|
|
|
_.isEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc1._id, a: 1, hello: 'world' }) |
|
|
|
_.isEqual(docs[1], { _id: doc3._id, a: 3, hello: 'moto' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[1], { _id: doc3._id, a: 3, hello: 'moto' }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1997,7 +2000,7 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.length.should.equal(1) |
|
|
|
docs.length.should.equal(1) |
|
|
|
_.isEqual(docs[0], { _id: doc2._id, a: 2, hello: 'earth' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc2._id, a: 2, hello: 'earth' }) |
|
|
|
|
|
|
|
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
// Even after a reload the database state hasn't changed
|
|
|
|
d.loadDatabase(function (err) { |
|
|
|
d.loadDatabase(function (err) { |
|
|
@ -2006,7 +2009,7 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
docs.length.should.equal(1) |
|
|
|
docs.length.should.equal(1) |
|
|
|
_.isEqual(docs[0], { _id: doc2._id, a: 2, hello: 'earth' }).should.equal(true) |
|
|
|
assert.deepStrictEqual(docs[0], { _id: doc2._id, a: 2, hello: 'earth' }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2030,9 +2033,9 @@ describe('Database', function () { |
|
|
|
nr.should.equal(1) |
|
|
|
nr.should.equal(1) |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
const d1 = _.find(docs, function (doc) { return doc._id === doc1._id }) |
|
|
|
const d1 = docs.find(function (doc) { return doc._id === doc1._id }) |
|
|
|
const d2 = _.find(docs, function (doc) { return doc._id === doc2._id }) |
|
|
|
const d2 = docs.find(function (doc) { return doc._id === doc2._id }) |
|
|
|
const d3 = _.find(docs, function (doc) { return doc._id === doc3._id }) |
|
|
|
const d3 = docs.find(function (doc) { return doc._id === doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
d1.a.should.equal(1) |
|
|
|
d1.a.should.equal(1) |
|
|
|
assert.isUndefined(d2) |
|
|
|
assert.isUndefined(d2) |
|
|
@ -2061,7 +2064,7 @@ describe('Database', function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.getAllData().length.should.equal(3) |
|
|
|
d.getAllData().length.should.equal(3) |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(Object.keys(d.indexes), ['_id']) |
|
|
|
assert.deepStrictEqual(Object.keys(d.indexes), ['_id']) |
|
|
|
|
|
|
|
|
|
|
|
d.ensureIndex({ fieldName: 'z' }) |
|
|
|
d.ensureIndex({ fieldName: 'z' }) |
|
|
|
d.indexes.z.fieldName.should.equal('z') |
|
|
|
d.indexes.z.fieldName.should.equal('z') |
|
|
@ -2122,7 +2125,7 @@ describe('Database', function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.getAllData().length.should.equal(2) |
|
|
|
d.getAllData().length.should.equal(2) |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(Object.keys(d.indexes), ['_id']) |
|
|
|
assert.deepStrictEqual(Object.keys(d.indexes), ['_id']) |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ z: '12', yes: 'yes' }, function (err, newDoc1) { |
|
|
|
d.insert({ z: '12', yes: 'yes' }, function (err, newDoc1) { |
|
|
@ -2130,7 +2133,7 @@ describe('Database', function () { |
|
|
|
d.insert({ z: '14', nope: 'nope' }, function (err, newDoc2) { |
|
|
|
d.insert({ z: '14', nope: 'nope' }, function (err, newDoc2) { |
|
|
|
d.remove({ z: '2' }, {}, function () { |
|
|
|
d.remove({ z: '2' }, {}, function () { |
|
|
|
d.update({ z: '1' }, { $set: { yes: 'yep' } }, {}, function () { |
|
|
|
d.update({ z: '1' }, { $set: { yes: 'yep' } }, {}, function () { |
|
|
|
assert.deepEqual(Object.keys(d.indexes), ['_id']) |
|
|
|
assert.deepStrictEqual(Object.keys(d.indexes), ['_id']) |
|
|
|
|
|
|
|
|
|
|
|
d.ensureIndex({ fieldName: 'z' }) |
|
|
|
d.ensureIndex({ fieldName: 'z' }) |
|
|
|
d.indexes.z.fieldName.should.equal('z') |
|
|
|
d.indexes.z.fieldName.should.equal('z') |
|
|
@ -2146,15 +2149,15 @@ describe('Database', function () { |
|
|
|
// The data in the z index is correct
|
|
|
|
// The data in the z index is correct
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
const doc0 = _.find(docs, function (doc) { return doc._id === 'aaa' }) |
|
|
|
const doc0 = docs.find(function (doc) { return doc._id === 'aaa' }) |
|
|
|
const doc1 = _.find(docs, function (doc) { return doc._id === newDoc1._id }) |
|
|
|
const doc1 = docs.find(function (doc) { return doc._id === newDoc1._id }) |
|
|
|
const doc2 = _.find(docs, function (doc) { return doc._id === newDoc2._id }) |
|
|
|
const doc2 = docs.find(function (doc) { return doc._id === newDoc2._id }) |
|
|
|
|
|
|
|
|
|
|
|
docs.length.should.equal(3) |
|
|
|
docs.length.should.equal(3) |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(doc0, { _id: 'aaa', z: '1', a: 2, ages: [1, 5, 12], yes: 'yep' }) |
|
|
|
assert.deepStrictEqual(doc0, { _id: 'aaa', z: '1', a: 2, ages: [1, 5, 12], yes: 'yep' }) |
|
|
|
assert.deepEqual(doc1, { _id: newDoc1._id, z: '12', yes: 'yes' }) |
|
|
|
assert.deepStrictEqual(doc1, { _id: newDoc1._id, z: '12', yes: 'yes' }) |
|
|
|
assert.deepEqual(doc2, { _id: newDoc2._id, z: '14', nope: 'nope' }) |
|
|
|
assert.deepStrictEqual(doc2, { _id: newDoc2._id, z: '14', nope: 'nope' }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2182,9 +2185,9 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
fs.writeFile(testDb, rawData, 'utf8', function () { |
|
|
|
fs.writeFile(testDb, rawData, 'utf8', function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
const doc1 = _.find(d.getAllData(), function (doc) { return doc.z === '1' }) |
|
|
|
const doc1 = d.getAllData().find(function (doc) { return doc.z === '1' }) |
|
|
|
const doc2 = _.find(d.getAllData(), function (doc) { return doc.z === '2' }) |
|
|
|
const doc2 = d.getAllData().find(function (doc) { return doc.z === '2' }) |
|
|
|
const doc3 = _.find(d.getAllData(), function (doc) { return doc.z === '3' }) |
|
|
|
const doc3 = d.getAllData().find(function (doc) { return doc.z === '3' }) |
|
|
|
|
|
|
|
|
|
|
|
d.getAllData().length.should.equal(3) |
|
|
|
d.getAllData().length.should.equal(3) |
|
|
|
|
|
|
|
|
|
|
@ -2212,9 +2215,9 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
fs.writeFile(testDb, rawData, 'utf8', function () { |
|
|
|
fs.writeFile(testDb, rawData, 'utf8', function () { |
|
|
|
d.loadDatabase(function (err) { |
|
|
|
d.loadDatabase(function (err) { |
|
|
|
const doc1 = _.find(d.getAllData(), function (doc) { return doc.z === '1' }) |
|
|
|
const doc1 = d.getAllData().find(function (doc) { return doc.z === '1' }) |
|
|
|
const doc2 = _.find(d.getAllData(), function (doc) { return doc.z === '2' }) |
|
|
|
const doc2 = d.getAllData().find(function (doc) { return doc.z === '2' }) |
|
|
|
const doc3 = _.find(d.getAllData(), function (doc) { return doc.z === '3' }) |
|
|
|
const doc3 = d.getAllData().find(function (doc) { return doc.z === '3' }) |
|
|
|
|
|
|
|
|
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
d.getAllData().length.should.equal(3) |
|
|
|
d.getAllData().length.should.equal(3) |
|
|
@ -2268,7 +2271,7 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
d.ensureIndex({ fieldName: 'a', unique: true }, function (err) { |
|
|
|
d.ensureIndex({ fieldName: 'a', unique: true }, function (err) { |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
assert.deepEqual(Object.keys(d.indexes), ['_id', 'b']) |
|
|
|
assert.deepStrictEqual(Object.keys(d.indexes), ['_id', 'b']) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2304,12 +2307,12 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ a: 5, z: 'nope' }, function (err, newDoc) { |
|
|
|
d.insert({ a: 5, z: 'nope' }, function (err, newDoc) { |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(2) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(2) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('nope'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('nope'), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2325,15 +2328,15 @@ describe('Database', function () { |
|
|
|
d.insert({ a: 2, z: 'yes', ya: 'indeed' }, function (err, newDoc) { |
|
|
|
d.insert({ a: 2, z: 'yes', ya: 'indeed' }, function (err, newDoc) { |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.ya.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.ya.tree.getNumberOfKeys().should.equal(1) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepEqual(d.indexes.ya.getMatching('indeed'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.ya.getMatching('indeed'), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ a: 5, z: 'nope', ya: 'sure' }, function (err, newDoc2) { |
|
|
|
d.insert({ a: 5, z: 'nope', ya: 'sure' }, function (err, newDoc2) { |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(2) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(2) |
|
|
|
d.indexes.ya.tree.getNumberOfKeys().should.equal(2) |
|
|
|
d.indexes.ya.tree.getNumberOfKeys().should.equal(2) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('nope'), [newDoc2]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('nope'), [newDoc2]) |
|
|
|
assert.deepEqual(d.indexes.ya.getMatching('sure'), [newDoc2]) |
|
|
|
assert.deepStrictEqual(d.indexes.ya.getMatching('sure'), [newDoc2]) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2347,12 +2350,12 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ a: 5, z: 'yes' }, function (err, newDoc2) { |
|
|
|
d.insert({ a: 5, z: 'yes' }, function (err, newDoc2) { |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('yes'), [newDoc, newDoc2]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('yes'), [newDoc, newDoc2]) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2366,7 +2369,7 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
d.insert({ a: 5, z: 'yes' }, function (err) { |
|
|
|
d.insert({ a: 5, z: 'yes' }, function (err) { |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
@ -2374,13 +2377,13 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
// Index didn't change
|
|
|
|
// Index didn't change
|
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(1) |
|
|
|
assert.deepEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.z.getMatching('yes'), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
// Data didn't change
|
|
|
|
// Data didn't change
|
|
|
|
assert.deepEqual(d.getAllData(), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.getAllData(), [newDoc]) |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.getAllData().length.should.equal(1) |
|
|
|
d.getAllData().length.should.equal(1) |
|
|
|
assert.deepEqual(d.getAllData()[0], newDoc) |
|
|
|
assert.deepStrictEqual(d.getAllData()[0], newDoc) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2407,9 +2410,9 @@ describe('Database', function () { |
|
|
|
d.indexes.uni.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.uni.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.nonu2.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.nonu2.tree.getNumberOfKeys().should.equal(1) |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(d.indexes.nonu1.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.nonu1.getMatching('yes'), [newDoc]) |
|
|
|
assert.deepEqual(d.indexes.uni.getMatching('willfail'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.uni.getMatching('willfail'), [newDoc]) |
|
|
|
assert.deepEqual(d.indexes.nonu2.getMatching('yes2'), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.nonu2.getMatching('yes2'), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2423,7 +2426,7 @@ describe('Database', function () { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.insert({ a: 2, z: 'yes' }, function (err, newDoc) { |
|
|
|
d.indexes.zzz.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.zzz.tree.getNumberOfKeys().should.equal(1) |
|
|
|
assert.deepEqual(d.indexes.zzz.getMatching(undefined), [newDoc]) |
|
|
|
assert.deepStrictEqual(d.indexes.zzz.getMatching(undefined), [newDoc]) |
|
|
|
|
|
|
|
|
|
|
|
d.insert({ a: 5, z: 'other' }, function (err) { |
|
|
|
d.insert({ a: 5, z: 'other' }, function (err) { |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
@ -2452,8 +2455,8 @@ describe('Database', function () { |
|
|
|
d.insert({ a: 2, b: 'si' }, function (err, doc2) { |
|
|
|
d.insert({ a: 2, b: 'si' }, function (err, doc2) { |
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
// eslint-disable-next-line node/handle-callback-err
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(doc1, _.find(docs, function (d) { return d._id === doc1._id })) |
|
|
|
assert.deepStrictEqual(doc1, docs.find(function (d) { return d._id === doc1._id })) |
|
|
|
assert.deepEqual(doc2, _.find(docs, function (d) { return d._id === doc2._id })) |
|
|
|
assert.deepStrictEqual(doc2, docs.find(function (d) { return d._id === doc2._id })) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2523,27 +2526,27 @@ describe('Database', function () { |
|
|
|
d.insert({ a: 2, b: 'si' }, function (err, _doc2) { |
|
|
|
d.insert({ a: 2, b: 'si' }, function (err, _doc2) { |
|
|
|
d.update({ a: 1 }, { $set: { a: 456, b: 'no' } }, {}, function (err, nr) { |
|
|
|
d.update({ a: 1 }, { $set: { a: 456, b: 'no' } }, {}, function (err, nr) { |
|
|
|
const data = d.getAllData() |
|
|
|
const data = d.getAllData() |
|
|
|
const doc1 = _.find(data, function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc1 = data.find(function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc2 = _.find(data, function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (doc) { return doc._id === _doc2._id }) |
|
|
|
|
|
|
|
|
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
nr.should.equal(1) |
|
|
|
nr.should.equal(1) |
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2) |
|
|
|
data.length.should.equal(2) |
|
|
|
assert.deepEqual(doc1, { a: 456, b: 'no', _id: _doc1._id }) |
|
|
|
assert.deepStrictEqual(doc1, { a: 456, b: 'no', _id: _doc1._id }) |
|
|
|
assert.deepEqual(doc2, { a: 2, b: 'si', _id: _doc2._id }) |
|
|
|
assert.deepStrictEqual(doc2, { a: 2, b: 'si', _id: _doc2._id }) |
|
|
|
|
|
|
|
|
|
|
|
d.update({}, { $inc: { a: 10 }, $set: { b: 'same' } }, { multi: true }, function (err, nr) { |
|
|
|
d.update({}, { $inc: { a: 10 }, $set: { b: 'same' } }, { multi: true }, function (err, nr) { |
|
|
|
const data = d.getAllData() |
|
|
|
const data = d.getAllData() |
|
|
|
const doc1 = _.find(data, function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc1 = data.find(function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc2 = _.find(data, function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (doc) { return doc._id === _doc2._id }) |
|
|
|
|
|
|
|
|
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
nr.should.equal(2) |
|
|
|
nr.should.equal(2) |
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2) |
|
|
|
data.length.should.equal(2) |
|
|
|
assert.deepEqual(doc1, { a: 466, b: 'same', _id: _doc1._id }) |
|
|
|
assert.deepStrictEqual(doc1, { a: 466, b: 'same', _id: _doc1._id }) |
|
|
|
assert.deepEqual(doc2, { a: 12, b: 'same', _id: _doc2._id }) |
|
|
|
assert.deepStrictEqual(doc2, { a: 12, b: 'same', _id: _doc2._id }) |
|
|
|
|
|
|
|
|
|
|
|
done() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
@ -2593,8 +2596,8 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
|
|
d.indexes.b.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.b.tree.getNumberOfKeys().should.equal(1) |
|
|
|
d.indexes.b.getMatching('same').length.should.equal(2) |
|
|
|
d.indexes.b.getMatching('same').length.should.equal(2) |
|
|
|
_.pluck(d.indexes.b.getMatching('same'), '_id').should.contain(doc1._id) |
|
|
|
d.indexes.b.getMatching('same').map(x => x._id).should.contain(doc1._id) |
|
|
|
_.pluck(d.indexes.b.getMatching('same'), '_id').should.contain(doc2._id) |
|
|
|
d.indexes.b.getMatching('same').map(x => x._id).should.contain(doc2._id) |
|
|
|
|
|
|
|
|
|
|
|
// The same pointers are shared between all indexes
|
|
|
|
// The same pointers are shared between all indexes
|
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(2) |
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(2) |
|
|
@ -2626,17 +2629,17 @@ describe('Database', function () { |
|
|
|
// Will conflict with doc3
|
|
|
|
// Will conflict with doc3
|
|
|
|
d.update({ a: 2 }, { $inc: { a: 10, c: 1000 }, $set: { b: 30 } }, {}, function (err) { |
|
|
|
d.update({ a: 2 }, { $inc: { a: 10, c: 1000 }, $set: { b: 30 } }, {}, function (err) { |
|
|
|
const data = d.getAllData() |
|
|
|
const data = d.getAllData() |
|
|
|
const doc1 = _.find(data, function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc1 = data.find(function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc2 = _.find(data, function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc3 = _.find(data, function (doc) { return doc._id === _doc3._id }) |
|
|
|
const doc3 = data.find(function (doc) { return doc._id === _doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
|
|
|
|
|
|
|
|
// Data left unchanged
|
|
|
|
// Data left unchanged
|
|
|
|
data.length.should.equal(3) |
|
|
|
data.length.should.equal(3) |
|
|
|
assert.deepEqual(doc1, { a: 1, b: 10, c: 100, _id: _doc1._id }) |
|
|
|
assert.deepStrictEqual(doc1, { a: 1, b: 10, c: 100, _id: _doc1._id }) |
|
|
|
assert.deepEqual(doc2, { a: 2, b: 20, c: 200, _id: _doc2._id }) |
|
|
|
assert.deepStrictEqual(doc2, { a: 2, b: 20, c: 200, _id: _doc2._id }) |
|
|
|
assert.deepEqual(doc3, { a: 3, b: 30, c: 300, _id: _doc3._id }) |
|
|
|
assert.deepStrictEqual(doc3, { a: 3, b: 30, c: 300, _id: _doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
// All indexes left unchanged and pointing to the same docs
|
|
|
|
// All indexes left unchanged and pointing to the same docs
|
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(3) |
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(3) |
|
|
@ -2678,17 +2681,17 @@ describe('Database', function () { |
|
|
|
$set: { b: 30 } |
|
|
|
$set: { b: 30 } |
|
|
|
}, { multi: true }, function (err) { |
|
|
|
}, { multi: true }, function (err) { |
|
|
|
const data = d.getAllData() |
|
|
|
const data = d.getAllData() |
|
|
|
const doc1 = _.find(data, function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc1 = data.find(function (doc) { return doc._id === _doc1._id }) |
|
|
|
const doc2 = _.find(data, function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc3 = _.find(data, function (doc) { return doc._id === _doc3._id }) |
|
|
|
const doc3 = data.find(function (doc) { return doc._id === _doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
err.errorType.should.equal('uniqueViolated') |
|
|
|
|
|
|
|
|
|
|
|
// Data left unchanged
|
|
|
|
// Data left unchanged
|
|
|
|
data.length.should.equal(3) |
|
|
|
data.length.should.equal(3) |
|
|
|
assert.deepEqual(doc1, { a: 1, b: 10, c: 100, _id: _doc1._id }) |
|
|
|
assert.deepStrictEqual(doc1, { a: 1, b: 10, c: 100, _id: _doc1._id }) |
|
|
|
assert.deepEqual(doc2, { a: 2, b: 20, c: 200, _id: _doc2._id }) |
|
|
|
assert.deepStrictEqual(doc2, { a: 2, b: 20, c: 200, _id: _doc2._id }) |
|
|
|
assert.deepEqual(doc3, { a: 3, b: 30, c: 300, _id: _doc3._id }) |
|
|
|
assert.deepStrictEqual(doc3, { a: 3, b: 30, c: 300, _id: _doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
// All indexes left unchanged and pointing to the same docs
|
|
|
|
// All indexes left unchanged and pointing to the same docs
|
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(3) |
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(3) |
|
|
@ -2726,15 +2729,15 @@ describe('Database', function () { |
|
|
|
d.insert({ a: 3, b: 'coin' }, function (err, _doc3) { |
|
|
|
d.insert({ a: 3, b: 'coin' }, function (err, _doc3) { |
|
|
|
d.remove({ a: 1 }, {}, function (err, nr) { |
|
|
|
d.remove({ a: 1 }, {}, function (err, nr) { |
|
|
|
const data = d.getAllData() |
|
|
|
const data = d.getAllData() |
|
|
|
const doc2 = _.find(data, function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc2 = data.find(function (doc) { return doc._id === _doc2._id }) |
|
|
|
const doc3 = _.find(data, function (doc) { return doc._id === _doc3._id }) |
|
|
|
const doc3 = data.find(function (doc) { return doc._id === _doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
assert.isNull(err) |
|
|
|
assert.isNull(err) |
|
|
|
nr.should.equal(1) |
|
|
|
nr.should.equal(1) |
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2) |
|
|
|
data.length.should.equal(2) |
|
|
|
assert.deepEqual(doc2, { a: 2, b: 'si', _id: _doc2._id }) |
|
|
|
assert.deepStrictEqual(doc2, { a: 2, b: 'si', _id: _doc2._id }) |
|
|
|
assert.deepEqual(doc3, { a: 3, b: 'coin', _id: _doc3._id }) |
|
|
|
assert.deepStrictEqual(doc3, { a: 3, b: 'coin', _id: _doc3._id }) |
|
|
|
|
|
|
|
|
|
|
|
d.remove({ a: { $in: [2, 3] } }, { multi: true }, function (err, nr) { |
|
|
|
d.remove({ a: { $in: [2, 3] } }, { multi: true }, function (err, nr) { |
|
|
|
const data = d.getAllData() |
|
|
|
const data = d.getAllData() |
|
|
|