Skip to content

Commit

Permalink
feat: remove reIndex
Browse files Browse the repository at this point in the history
The deprecated `collection.reIndex` helper has been removed.

NODE-2560
  • Loading branch information
emadum authored May 15, 2020
1 parent 34c9195 commit 6b510a6
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 337 deletions.
20 changes: 0 additions & 20 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const ListIndexesOperation = require('./operations/list_indexes');
const MapReduceOperation = require('./operations/map_reduce');
const OptionsOperation = require('./operations/options_operation');
const RenameOperation = require('./operations/rename');
const ReIndexOperation = require('./operations/re_index');
const ReplaceOneOperation = require('./operations/replace_one');
const StatsOperation = require('./operations/stats');
const UpdateManyOperation = require('./operations/update_many');
Expand Down Expand Up @@ -1377,25 +1376,6 @@ Collection.prototype.dropAllIndexes = deprecate(
'collection.dropAllIndexes is deprecated. Use dropIndexes instead.'
);

/**
* Reindex all indexes on the collection
* Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
*
* @function
* @param {object} [options] Optional settings
* @param {ClientSession} [options.session] optional session to use for this operation
* @param {Collection~resultCallback} [callback] The command result callback
* @returns {Promise} returns Promise if no callback passed
*/
Collection.prototype.reIndex = function(options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};

const reIndexOperation = new ReIndexOperation(this, options);

return executeOperation(this.s.topology, reIndexOperation, callback);
};

/**
* Get the list of all indexes information for the collection.
*
Expand Down
28 changes: 0 additions & 28 deletions lib/operations/re_index.js

This file was deleted.

70 changes: 0 additions & 70 deletions test/functional/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,76 +202,6 @@ describe('Db', function() {
}
});

/**
* An example showing how to force a reindex of a collection.
*/
it('shouldCorrectlyForceReindexOnCollection', {
metadata: {
requires: { topology: ['single'] }
},

test: function(done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });

// DOC_LINE var client = new MongoClient(new Server('localhost', 27017));
// DOC_START
// Establish connection to db
client.connect(function(err, client) {
var db = client.db('integration_tests');

// Create a collection we want to drop later
db.createCollection('create_and_drop_all_indexes', function(err, collection) {
test.equal(null, err);

// Insert a bunch of documents for the index
collection.insert(
[
{ a: 1, b: 1 },
{ a: 2, b: 2 },
{ a: 3, b: 3 },
{ a: 4, b: 4, c: 4 }
],
configuration.writeConcernMax(),
function(err) {
test.equal(null, err);

// Create an index on the a field
collection.ensureIndex(
{ a: 1, b: 1 },
{ unique: true, background: true, w: 1 },
function(err) {
test.equal(null, err);

// Force a reindex of the collection
collection.reIndex(function(err, result) {
test.equal(null, err);
test.equal(true, result);

// Verify that the index is gone
collection.indexInformation(function(err, indexInformation) {
test.deepEqual([['_id', 1]], indexInformation._id_);
test.deepEqual(
[
['a', 1],
['b', 1]
],
indexInformation.a_1_b_1
);

client.close(done);
});
});
}
);
}
);
});
});
// DOC_END
}
});

it('shouldCorrectlyGetErrorDroppingNonExistingDb', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
Expand Down
77 changes: 0 additions & 77 deletions test/functional/operation_example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2695,83 +2695,6 @@ describe('Operation Examples', function() {
}
});

/**
* An example showing how to force a reindex of a collection.
*
* @example-class Collection
* @example-method reIndex
*/
it('shouldCorrectlyIndexAndForceReindexOnCollection', {
metadata: {
requires: { topology: ['single', 'ssl', 'heap', 'wiredtiger'] }
},

test: function(done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
client.connect(function(err, client) {
// LINE var MongoClient = require('mongodb').MongoClient,
// LINE test = require('assert');
// LINE const client = new MongoClient('mongodb://localhost:27017/test');
// LINE client.connect(function(err, client) {
// LINE var db = client.db('test);
// REPLACE configuration.writeConcernMax() WITH {w:1}
// REMOVE-LINE restartAndDone
// REMOVE-LINE done();
// REMOVE-LINE var db = client.db(configuration.db);
// BEGIN
var db = client.db(configuration.db);
// Create a collection we want to drop later
var collection = db.collection('shouldCorrectlyForceReindexOnCollection');
// Insert a bunch of documents for the index
collection.insertMany(
[
{ a: 1, b: 1 },
{ a: 2, b: 2 },
{ a: 3, b: 3 },
{ a: 4, b: 4, c: 4 }
],
{ w: 1 },
function(err, result) {
test.ok(result);
test.equal(null, err);

// Create an index on the a field
collection.ensureIndex(
{ a: 1, b: 1 },
{ unique: true, background: true, w: 1 },
function(err, indexName) {
test.ok(indexName);
test.equal(null, err);

// Force a reindex of the collection
collection.reIndex(function(err, result) {
test.equal(null, err);
test.equal(true, result);

// Verify that the index is gone
collection.indexInformation(function(err, indexInformation) {
test.deepEqual([['_id', 1]], indexInformation._id_);
test.deepEqual(
[
['a', 1],
['b', 1]
],
indexInformation.a_1_b_1
);

client.close(done);
});
});
}
);
}
);
});
// END
}
});

/**
* An example removing all documents in a collection not using safe mode
*
Expand Down
68 changes: 0 additions & 68 deletions test/functional/operation_generators_example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1982,74 +1982,6 @@ describe('Operation (Generators)', function() {
}
});

/**
* An example showing how to force a reindex of a collection using a Generator and the co module.
*
* @example-class Collection
* @example-method reIndex
*/
it('shouldCorrectlyIndexAndForceReindexOnCollectionWithGenerators', {
metadata: { requires: { generators: true, topology: ['single'] } },

test: function() {
var configuration = this.configuration;
var co = require('co');

return co(function*() {
// Connect
var client = yield configuration
.newClient(configuration.writeConcernMax(), { poolSize: 1 })
.connect();
var db = client.db(configuration.db);
// LINE var MongoClient = require('mongodb').MongoClient,
// LINE co = require('co');
// LINE test = require('assert');
// LINE
// LINE co(function*() {
// LINE const client = new MongoClient('mongodb://localhost:27017/test');
// LINE yield client.connect();
// LINE
// LINE var db = client.db('test');
// REPLACE configuration.writeConcernMax() WITH {w:1}
// BEGIN

// Create a collection we want to drop later
var collection = db.collection('shouldCorrectlyForceReindexOnCollection_with_generators');
// Insert a bunch of documents for the index
yield collection.insertMany(
[
{ a: 1, b: 1 },
{ a: 2, b: 2 },
{ a: 3, b: 3 },
{ a: 4, b: 4, c: 4 }
],
{ w: 1 }
);

// Create an index on the a field
yield collection.ensureIndex({ a: 1, b: 1 }, { unique: true, background: true, w: 1 });

// Force a reindex of the collection
var result = yield collection.reIndex();
test.equal(true, result);

// Verify that the index is gone
var indexInformation = yield collection.indexInformation();
test.deepEqual([['_id', 1]], indexInformation._id_);
test.deepEqual(
[
['a', 1],
['b', 1]
],
indexInformation.a_1_b_1
);

yield client.close();
});
// END
}
});

/**
* An example removing all documents in a collection not using safe mode using a Generator and the co module.
*
Expand Down
74 changes: 0 additions & 74 deletions test/functional/operation_promises_example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2035,80 +2035,6 @@ describe('Operation (Promises)', function() {
}
});

/**
* An example showing how to force a reindex of a collection using a Promise.
*
* @example-class Collection
* @example-method reIndex
*/
it('shouldCorrectlyIndexAndForceReindexOnCollectionWithPromises', {
metadata: { requires: { topology: ['single'] } },

test: function() {
var configuration = this.configuration;
var client = configuration.newClient({ w: 0 }, { poolSize: 1, auto_reconnect: true });

return client.connect().then(function(client) {
var db = client.db(configuration.db);
// LINE var MongoClient = require('mongodb').MongoClient,
// LINE test = require('assert');
// LINE const client = new MongoClient('mongodb://localhost:27017/test');
// LINE client.connect().then(() => {
// LINE var db = client.db('test);
// REPLACE configuration.writeConcernMax() WITH {w:1}
// REMOVE-LINE done();
// BEGIN

// Create a collection we want to drop later
var collection = db.collection('shouldCorrectlyForceReindexOnCollection_with_promise');

// Insert a bunch of documents for the index
return collection
.insertMany(
[
{ a: 1, b: 1 },
{ a: 2, b: 2 },
{ a: 3, b: 3 },
{ a: 4, b: 4, c: 4 }
],
{
w: 1
}
)
.then(function(result) {
test.ok(result);

// Create an index on the a field
return collection.ensureIndex({ a: 1, b: 1 }, { unique: true, background: true, w: 1 });
})
.then(function(indexName) {
test.ok(indexName);

// Force a reindex of the collection
return collection.reIndex();
})
.then(function(result) {
test.equal(true, result);

// Verify that the index is gone
return collection.indexInformation();
})
.then(function(indexInformation) {
test.deepEqual([['_id', 1]], indexInformation._id_);
test.deepEqual(
[
['a', 1],
['b', 1]
],
indexInformation.a_1_b_1
);
return client.close();
});
});
// END
}
});

/**
* An example removing all documents in a collection not using safe mode using a Promise.
*
Expand Down

0 comments on commit 6b510a6

Please sign in to comment.