@@ -1032,8 +1032,6 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
1032
1032
options = options == null ? { } : options ;
1033
1033
// Shallow clone the options
1034
1034
options = shallowClone ( options ) ;
1035
- // Run only against primary
1036
- options . readPreference = ReadPreference . PRIMARY ;
1037
1035
1038
1036
// If we have a callback fallback
1039
1037
if ( typeof callback == 'function' ) return createIndex ( self , name , fieldOrSpec , options , callback ) ;
@@ -1048,12 +1046,15 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
1048
1046
1049
1047
var createIndex = function ( self , name , fieldOrSpec , options , callback ) {
1050
1048
// Get the write concern options
1051
- var finalOptions = writeConcern ( { } , self , options ) ;
1049
+ var finalOptions = writeConcern ( { } , self , options , { readPreference : ReadPreference . PRIMARY } ) ;
1052
1050
// Ensure we have a callback
1053
1051
if ( finalOptions . writeConcern && typeof callback != 'function' ) {
1054
1052
throw MongoError . create ( { message : "Cannot use a writeConcern without a provided callback" , driver :true } ) ;
1055
1053
}
1056
1054
1055
+ // Run only against primary
1056
+ options . readPreference = ReadPreference . PRIMARY ;
1057
+
1057
1058
// Did the user destroy the topology
1058
1059
if ( self . serverConfig && self . serverConfig . isDestroyed ( ) ) return callback ( new MongoError ( 'topology was destroyed' ) ) ;
1059
1060
@@ -1136,6 +1137,9 @@ var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
1136
1137
// Did the user destroy the topology
1137
1138
if ( self . serverConfig && self . serverConfig . isDestroyed ( ) ) return callback ( new MongoError ( 'topology was destroyed' ) ) ;
1138
1139
1140
+ // Merge primary readPreference
1141
+ finalOptions . readPreference = ReadPreference . PRIMARY
1142
+
1139
1143
// Check if the index allready exists
1140
1144
self . indexInformation ( name , finalOptions , function ( err , indexInformation ) {
1141
1145
if ( err != null && err . code != 26 ) return handleCallback ( callback , err , null ) ;
@@ -1645,7 +1649,6 @@ var indexInformation = function(self, name, options, callback) {
1645
1649
1646
1650
// Did the user destroy the topology
1647
1651
if ( self . serverConfig && self . serverConfig . isDestroyed ( ) ) return callback ( new MongoError ( 'topology was destroyed' ) ) ;
1648
-
1649
1652
// Process all the results from the index command and collection
1650
1653
var processResults = function ( indexes ) {
1651
1654
// Contains all the information
@@ -1664,7 +1667,7 @@ var indexInformation = function(self, name, options, callback) {
1664
1667
}
1665
1668
1666
1669
// Get the list of indexes of the specified collection
1667
- self . collection ( name ) . listIndexes ( ) . toArray ( function ( err , indexes ) {
1670
+ self . collection ( name ) . listIndexes ( options ) . toArray ( function ( err , indexes ) {
1668
1671
if ( err ) return callback ( toError ( err ) ) ;
1669
1672
if ( ! Array . isArray ( indexes ) ) return handleCallback ( callback , null , [ ] ) ;
1670
1673
if ( full ) return handleCallback ( callback , null , indexes ) ;
0 commit comments