@@ -1410,6 +1410,9 @@ var rename = function(self, newName, opt, callback) {
1410
1410
var dropTarget = typeof opt . dropTarget == 'boolean' ? opt . dropTarget : false ;
1411
1411
var cmd = { 'renameCollection' :renameCollection , 'to' :toCollection , 'dropTarget' :dropTarget } ;
1412
1412
1413
+ // Decorate command with writeConcern if supported
1414
+ decorateWithWriteConcern ( cmd , self , opt ) ;
1415
+
1413
1416
// Execute against admin
1414
1417
self . s . db . admin ( ) . command ( cmd , opt , function ( err , doc ) {
1415
1418
if ( err ) return handleCallback ( callback , err , null ) ;
@@ -1436,10 +1439,10 @@ define.classMethod('rename', {callback: true, promise:true});
1436
1439
Collection . prototype . drop = function ( options , callback ) {
1437
1440
var self = this ;
1438
1441
if ( typeof options == 'function' ) callback = options , options = { } ;
1439
- options = options | { } ;
1442
+ options = options || { } ;
1440
1443
1441
1444
// Execute using callback
1442
- if ( typeof callback == 'function' ) return self . s . db . dropCollection ( self . s . name , callback ) ;
1445
+ if ( typeof callback == 'function' ) return self . s . db . dropCollection ( self . s . name , options , callback ) ;
1443
1446
// Return a Promise
1444
1447
return new this . s . promiseLibrary ( function ( resolve , reject ) {
1445
1448
self . s . db . dropCollection ( self . s . name , options , function ( err , r ) {
@@ -1645,7 +1648,10 @@ Collection.prototype.dropIndex = function(indexName, options, callback) {
1645
1648
1646
1649
var dropIndex = function ( self , indexName , options , callback ) {
1647
1650
// Delete index command
1648
- var cmd = { 'deleteIndexes' :self . s . name , 'index' :indexName } ;
1651
+ var cmd = { 'dropIndexes' :self . s . name , 'index' :indexName } ;
1652
+
1653
+ // Decorate command with writeConcern if supported
1654
+ decorateWithWriteConcern ( cmd , self , options ) ;
1649
1655
1650
1656
// Execute command
1651
1657
self . s . db . command ( cmd , options , function ( err , result ) {
@@ -1663,11 +1669,15 @@ define.classMethod('dropIndex', {callback: true, promise:true});
1663
1669
* @param {Collection~resultCallback } [callback] The command result callback
1664
1670
* @return {Promise } returns Promise if no callback passed
1665
1671
*/
1666
- Collection . prototype . dropIndexes = function ( callback ) {
1672
+ Collection . prototype . dropIndexes = function ( options , callback ) {
1667
1673
var self = this ;
1668
1674
1675
+ // Do we have options
1676
+ if ( typeof options == 'function' ) callback = options , options = { } ;
1677
+ options = options || { } ;
1678
+
1669
1679
// Execute using callback
1670
- if ( typeof callback == 'function' ) return dropIndexes ( self , callback ) ;
1680
+ if ( typeof callback == 'function' ) return dropIndexes ( self , options , callback ) ;
1671
1681
1672
1682
// Return a Promise
1673
1683
return new this . s . promiseLibrary ( function ( resolve , reject ) {
@@ -1678,8 +1688,8 @@ Collection.prototype.dropIndexes = function(callback) {
1678
1688
} ) ;
1679
1689
}
1680
1690
1681
- var dropIndexes = function ( self , callback ) {
1682
- self . dropIndex ( '*' , function ( err , result ) {
1691
+ var dropIndexes = function ( self , options , callback ) {
1692
+ self . dropIndex ( '*' , options , function ( err , result ) {
1683
1693
if ( err ) return handleCallback ( callback , err , false ) ;
1684
1694
handleCallback ( callback , null , true ) ;
1685
1695
} ) ;
@@ -1726,6 +1736,9 @@ var reIndex = function(self, options, callback) {
1726
1736
// Reindex
1727
1737
var cmd = { 'reIndex' :self . s . name } ;
1728
1738
1739
+ // Decorate command with writeConcern if supported
1740
+ decorateWithWriteConcern ( cmd , self , options ) ;
1741
+
1729
1742
// Execute the command
1730
1743
self . s . db . command ( cmd , options , function ( err , result ) {
1731
1744
if ( callback == null ) return ;
@@ -1760,25 +1773,20 @@ Collection.prototype.listIndexes = function(options) {
1760
1773
throw new MongoError ( 'cannot connect to server' ) ;
1761
1774
}
1762
1775
1763
- // console.log("!!!!!!!!!!!!!! HEY 0")
1764
1776
// We have a list collections command
1765
1777
if ( this . s . topology . capabilities ( ) . hasListIndexesCommand ) {
1766
- // console.log("!!!!!!!!!!!!!! HEY 0:1")
1767
1778
// Cursor options
1768
1779
var cursor = options . batchSize ? { batchSize : options . batchSize } : { }
1769
1780
// Build the command
1770
1781
var command = { listIndexes : this . s . name , cursor : cursor } ;
1771
- // console.log("!!!!!!!!!!!!!! HEY 0:2")
1772
1782
// Execute the cursor
1773
1783
var cursor = this . s . topology . cursor ( f ( '%s.$cmd' , this . s . dbName ) , command , options ) ;
1774
1784
// Do we have a readPreference, apply it
1775
1785
if ( options . readPreference ) cursor . setReadPreference ( options . readPreference ) ;
1776
- // console.log("!!!!!!!!!!!!!! HEY 0:3")
1777
1786
// Return the cursor
1778
1787
return cursor ;
1779
1788
}
1780
1789
1781
- // console.log("!!!!!!!!!!!!!! HEY 1")
1782
1790
// Get the namespace
1783
1791
var ns = f ( '%s.system.indexes' , this . s . dbName ) ;
1784
1792
// Get the query
@@ -2452,6 +2460,18 @@ var findAndRemove = function(self, query, sort, options, callback) {
2452
2460
2453
2461
define . classMethod ( 'findAndRemove' , { callback : true , promise :true } ) ;
2454
2462
2463
+ function decorateWithWriteConcern ( command , self , options ) {
2464
+ // Do we support write concerns 3.4 and higher
2465
+ if ( self . s . topology . capabilities ( ) . commandsTakeWriteConcern ) {
2466
+ // Get the write concern settings
2467
+ var finalOptions = writeConcern ( shallowClone ( options ) , self . s . db , self , options ) ;
2468
+ // Add the write concern to the command
2469
+ if ( finalOptions . writeConcern ) {
2470
+ command . writeConcern = finalOptions . writeConcern ;
2471
+ }
2472
+ }
2473
+ }
2474
+
2455
2475
/**
2456
2476
* Execute an aggregation framework pipeline against the collection, needs MongoDB >= 2.2
2457
2477
* @method
@@ -2469,6 +2489,7 @@ define.classMethod('findAndRemove', {callback: true, promise:true});
2469
2489
*/
2470
2490
Collection . prototype . aggregate = function ( pipeline , options , callback ) {
2471
2491
var self = this ;
2492
+
2472
2493
if ( Array . isArray ( pipeline ) ) {
2473
2494
// Set up callback if one is provided
2474
2495
if ( typeof options == 'function' ) {
@@ -2510,6 +2531,9 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
2510
2531
// Build the command
2511
2532
var command = { aggregate : this . s . name , pipeline : pipeline } ;
2512
2533
2534
+ // Decorate command with writeConcern if supported
2535
+ decorateWithWriteConcern ( command , self , options ) ;
2536
+
2513
2537
// If we have bypassDocumentValidation set
2514
2538
if ( typeof options . bypassDocumentValidation == 'boolean' ) {
2515
2539
command . bypassDocumentValidation = options . bypassDocumentValidation ;
@@ -3085,7 +3109,10 @@ var mapReduce = function(self, map, reduce, options, callback) {
3085
3109
// If we have a read preference and inline is not set as output fail hard
3086
3110
if ( ( options . readPreference != false && options . readPreference != 'primary' )
3087
3111
&& options [ 'out' ] && ( options [ 'out' ] . inline != 1 && options [ 'out' ] != 'inline' ) ) {
3112
+ // Force readPreference to primary
3088
3113
options . readPreference = 'primary' ;
3114
+ // Decorate command with writeConcern if supported
3115
+ decorateWithWriteConcern ( mapCommandHash , self , options ) ;
3089
3116
} else if ( self . s . readConcern ) {
3090
3117
mapCommandHash . readConcern = self . s . readConcern ;
3091
3118
}
0 commit comments