@@ -2,6 +2,7 @@ var expect = require('chai').expect;
22var ShareDbMongo = require ( '..' ) ;
33var getQuery = require ( 'sharedb-mingo-memory/get-query' ) ;
44var async = require ( 'async' ) ;
5+ var randomUUID = require ( 'crypto' ) . randomUUID ;
56
67var mongoUrl = process . env . TEST_MONGO_URL || 'mongodb://localhost:27017/test' ;
78
@@ -432,6 +433,50 @@ describe('mongo db', function() {
432433 } ) ;
433434} ) ;
434435
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+
435480describe ( 'mongo db connection' , function ( ) {
436481 describe ( 'via url string' , function ( ) {
437482 beforeEach ( function ( done ) {
0 commit comments