sharedb-mongo 4.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -384,7 +384,7 @@ ShareDbMongo.prototype.getOpCollection = function(collectionName, callback) {
384
384
  var collection = mongo.collection(name);
385
385
  // Given the potential problems with creating indexes on the fly, it might
386
386
  // be preferrable to disable automatic creation
387
- if (self.disableIndexCreation) {
387
+ if (self.disableIndexCreation === true) {
388
388
  return callback(null, collection);
389
389
  }
390
390
  if (self.opIndexes[collectionName]) {
@@ -398,10 +398,13 @@ ShareDbMongo.prototype.getOpCollection = function(collectionName, callback) {
398
398
  // collection this won't be a problem, but this is a dangerous mechanism.
399
399
  // Perhaps we should only warn instead of creating the indexes, especially
400
400
  // when there is a lot of data in the collection.
401
- collection.createIndex({d: 1, v: 1}, {background: true})
402
- .then(function() {
403
- return collection.createIndex({src: 1, seq: 1, v: 1}, {background: true});
404
- })
401
+
402
+ var disabledIndexes = self.disableIndexCreation || {};
403
+ var promises = [
404
+ collection.createIndex({d: 1, v: 1}, {background: true}),
405
+ !disabledIndexes.src_seq_v && collection.createIndex({src: 1, seq: 1, v: 1}, {background: true})
406
+ ];
407
+ Promise.all(promises)
405
408
  .then(function() {
406
409
  self.opIndexes[collectionName] = true;
407
410
  callback(null, collection);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sharedb-mongo",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "description": "MongoDB database adapter for ShareDB",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -2,6 +2,7 @@ var expect = require('chai').expect;
2
2
  var ShareDbMongo = require('..');
3
3
  var getQuery = require('sharedb-mingo-memory/get-query');
4
4
  var async = require('async');
5
+ var randomUUID = require('crypto').randomUUID;
5
6
 
6
7
  var mongoUrl = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test';
7
8
 
@@ -432,6 +433,50 @@ describe('mongo db', function() {
432
433
  });
433
434
  });
434
435
 
436
+ describe('options', function() {
437
+ var db;
438
+
439
+ afterEach(function(done) {
440
+ db.close(done);
441
+ });
442
+
443
+ it('disables index creation', function(done) {
444
+ var collection = randomUUID();
445
+ db = new ShareDbMongo(mongoUrl, {disableIndexCreation: true});
446
+ async.waterfall([
447
+ db.commit.bind(db, collection, 'foo', {v: 0, create: {}}, {}, null),
448
+ function(succeeded, next) {
449
+ db.getDbs(next);
450
+ },
451
+ function(mongo, mongoPoll, next) {
452
+ mongo.collection('o_' + collection).indexInformation().then(function(indexes) {
453
+ expect(indexes['d_1_v_1']).not.to.be.ok;
454
+ expect(indexes['src_1_seq_1_v_1']).not.to.be.ok;
455
+ next();
456
+ });
457
+ }
458
+ ], done);
459
+ });
460
+
461
+ it('disables just the src,seq,v index', function(done) {
462
+ var collection = randomUUID();
463
+ db = new ShareDbMongo(mongoUrl, {disableIndexCreation: {src_seq_v: true}});
464
+ async.waterfall([
465
+ db.commit.bind(db, collection, 'foo', {v: 0, create: {}}, {}, null),
466
+ function(succeeded, next) {
467
+ db.getDbs(next);
468
+ },
469
+ function(mongo, mongoPoll, next) {
470
+ mongo.collection('o_' + collection).indexInformation().then(function(indexes) {
471
+ expect(indexes['d_1_v_1']).to.be.ok;
472
+ expect(indexes['src_1_seq_1_v_1']).not.to.be.ok;
473
+ next();
474
+ });
475
+ }
476
+ ], done);
477
+ });
478
+ });
479
+
435
480
  describe('mongo db connection', function() {
436
481
  describe('via url string', function() {
437
482
  beforeEach(function(done) {