Skip to content

Commit

Permalink
feat(geoHaystackSearch): remove geoHaystackSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum committed Apr 23, 2020
1 parent d3af3b3 commit 5a1b61c
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 397 deletions.
26 changes: 0 additions & 26 deletions lib/collection.js
Expand Up @@ -54,7 +54,6 @@ const FindAndModifyOperation = require('./operations/find_and_modify');
const FindOneAndDeleteOperation = require('./operations/find_one_and_delete');
const FindOneAndReplaceOperation = require('./operations/find_one_and_replace');
const FindOneAndUpdateOperation = require('./operations/find_one_and_update');
const GeoHaystackSearchOperation = require('./operations/geo_haystack_search');
const IndexesOperation = require('./operations/indexes');
const IndexExistsOperation = require('./operations/index_exists');
const IndexInformationOperation = require('./operations/index_information');
Expand Down Expand Up @@ -2027,31 +2026,6 @@ Collection.prototype.parallelCollectionScan = deprecate(function(options, callba
);
}, 'parallelCollectionScan is deprecated in MongoDB v4.1');

/**
* Execute a geo search using a geo haystack index on a collection.
*
* @function
* @param {number} x Point to search on the x axis, ensure the indexes are ordered in the same order.
* @param {number} y Point to search on the y axis, ensure the indexes are ordered in the same order.
* @param {object} [options] Optional settings.
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
* @param {number} [options.maxDistance] Include results up to maxDistance from the point.
* @param {object} [options.search] Filter the results by a query.
* @param {number} [options.limit=false] Max number of results to return.
* @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.geoHaystackSearch = function(x, y, options, callback) {
const args = Array.prototype.slice.call(arguments, 2);
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
options = args.length ? args.shift() || {} : {};

const geoHaystackSearchOperation = new GeoHaystackSearchOperation(this, x, y, options);

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

/**
* Run a group command across a collection
*
Expand Down
79 changes: 0 additions & 79 deletions lib/operations/geo_haystack_search.js

This file was deleted.

3 changes: 1 addition & 2 deletions lib/sessions.js
Expand Up @@ -651,8 +651,7 @@ function commandSupportsReadConcern(command, options) {
command.distinct ||
command.find ||
command.parallelCollectionScan ||
command.geoNear ||
command.geoSearch
command.geoNear
) {
return true;
}
Expand Down
29 changes: 0 additions & 29 deletions test/functional/core/error.test.js
@@ -1,38 +1,9 @@
'use strict';

const { expect } = require('chai');
const { format: f } = require('util');
const { MongoError, MongoNetworkError } = require('../../../lib/error');

describe('Error tests', function() {
it('should return helpful error when geoHaystack fails', {
metadata: {
requires: {
mongodb: '< 4.1.x',
topology: ['single', 'replicaset']
}
},

test: function(done) {
var self = this;
const config = this.configuration;
const server = config.newTopology();

var ns = f('%s.geohaystack1', self.configuration.db);
server.on('connect', function(_server) {
_server.command('system.$cmd', { geoNear: ns }, {}, function(_err, result) {
expect(result).to.not.exist;
expect(/can't find ns/.test(_err)).to.be.ok;
_server.destroy();
done();
});
});

// Start connection
server.connect();
}
});

it('should create a MongoError from string', {
metadata: {
requires: { topology: ['single'] }
Expand Down
64 changes: 0 additions & 64 deletions test/functional/operation_example.test.js
Expand Up @@ -1693,70 +1693,6 @@ describe('Operation Examples', function() {
}
});

/**
* Example of a simple geoHaystackSearch query across some documents
*
* @example-class Collection
* @example-method geoHaystackSearch
*/
it('shouldCorrectlyPerformSimpleGeoHaystackSearchCommand', {
metadata: { requires: { topology: ['single', 'replicaset'] } },

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);
// Fetch the collection
var collection = db.collection('simple_geo_haystack_command');

// Add a location based index
collection.ensureIndex({ loc: 'geoHaystack', type: 1 }, { bucketSize: 1 }, function(
err,
result
) {
test.ok(result);
test.equal(null, err);

// Save a new location tagged document
collection.insertMany(
[
{ a: 1, loc: [50, 30] },
{ a: 1, loc: [30, 50] }
],
configuration.writeConcernMax(),
function(err, result) {
test.ok(result);
test.equal(null, err);

// Use geoHaystackSearch command to find document
collection.geoHaystackSearch(
50,
50,
{ search: { a: 1 }, limit: 1, maxDistance: 100 },
function(err, docs) {
test.equal(1, docs.results.length);
client.close(done);
}
);
}
);
});
});
// END
}
});

/**
* A simple map reduce example
*
Expand Down
59 changes: 0 additions & 59 deletions test/functional/operation_generators_example.test.js
Expand Up @@ -1050,65 +1050,6 @@ describe('Operation (Generators)', function() {
}
});

/**
* Example of a simple geoHaystackSearch query across some documents using a Generator and the co module.
*
* @example-class Collection
* @example-method geoHaystackSearch
*/
it('shouldCorrectlyPerformSimpleGeoHaystackSearchCommandWithGenerators', {
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

// Fetch the collection
var collection = db.collection('simple_geo_haystack_command_with_generators');

// Add a location based index
yield collection.ensureIndex({ loc: 'geoHaystack', type: 1 }, { bucketSize: 1 });

// Save a new location tagged document
yield collection.insertMany(
[
{ a: 1, loc: [50, 30] },
{ a: 1, loc: [30, 50] }
],
configuration.writeConcernMax()
);

// Use geoHaystackSearch command to find document
var docs = yield collection.geoHaystackSearch(50, 50, {
search: { a: 1 },
limit: 1,
maxDistance: 100
});
test.equal(1, docs.results.length);
yield client.close();
});
// END
}
});

/**
* A simple map reduce example using a Generator and the co module.
*
Expand Down
61 changes: 0 additions & 61 deletions test/functional/operation_promises_example.test.js
Expand Up @@ -1076,67 +1076,6 @@ describe('Operation (Promises)', function() {
}
});

/**
* Example of a simple geoHaystackSearch query across some documents using a Promise.
*
* @example-class Collection
* @example-method geoHaystackSearch
*/
it('shouldCorrectlyPerformSimpleGeoHaystackSearchCommandWithPromises', {
metadata: { requires: { topology: ['single', 'replicaset'] } },

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

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

// Fetch the collection
var collection = db.collection('simple_geo_haystack_command_with_promise');

// Add a location based index
return collection
.ensureIndex({ loc: 'geoHaystack', type: 1 }, { bucketSize: 1 })
.then(function(result) {
test.ok(result);

// Save a new location tagged document
return collection.insertMany(
[
{ a: 1, loc: [50, 30] },
{ a: 1, loc: [30, 50] }
],
configuration.writeConcernMax()
);
})
.then(function(result) {
test.ok(result);

// Use geoHaystackSearch command to find document
return collection.geoHaystackSearch(50, 50, {
search: { a: 1 },
limit: 1,
maxDistance: 100
});
})
.then(function(docs) {
test.equal(1, docs.results.length);
return client.close();
});
});
// END
}
});

/**
* A simple map reduce example using a Promise.
*
Expand Down

0 comments on commit 5a1b61c

Please sign in to comment.