diff options
author | Randolph Tan <randolph@10gen.com> | 2014-01-14 14:09:42 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-02-28 16:26:33 -0500 |
commit | 5595b945603b0712c537787e31e6da661c424fee (patch) | |
tree | 90945ee3fe4931032f3af2d397bb755fbf5d30ef /jstests/core/geo_s2descindex.js | |
parent | cd62080dcb036e83f8fca6d68d9bcab67bf7a21c (diff) | |
download | mongo-5595b945603b0712c537787e31e6da661c424fee.tar.gz |
SERVER-12127 migrate js tests to jscore suite when not related to writes
Moved test jstest/[a-i].js -> jstests/core/ and made changes to comply with write command api
Diffstat (limited to 'jstests/core/geo_s2descindex.js')
-rw-r--r-- | jstests/core/geo_s2descindex.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/jstests/core/geo_s2descindex.js b/jstests/core/geo_s2descindex.js new file mode 100644 index 00000000000..39d153a6e55 --- /dev/null +++ b/jstests/core/geo_s2descindex.js @@ -0,0 +1,64 @@ +// +// Tests 2dsphere with descending fields, ensures correct lookup +// + +var coll = db.getCollection("twodspheredesc"); + +var descriptors = [["field1", -1], ["field2", -1], ["coordinates", "2dsphere"]] +var docA = {field1 : "a", field2 : 1, coordinates : [-118.2400013, 34.073893]} +var docB = {field1 : "b", field2 : 1, coordinates : [-118.2400012, 34.073894]} + +// Try both regular and near index cursors +var query = {coordinates : {$geoWithin : {$centerSphere : [[-118.240013, 34.073893], + 0.44915760491198753]}}}; +var queryNear = {coordinates : {$geoNear : {"type" : "Point", "coordinates" : [0, 0]}}}; + +// +// The idea here is we try "2dsphere" indexes in combination with descending +// other fields in various +// positions and ensure that we return correct results. +// + +for ( var t = 0; t < descriptors.length; t++) { + + var descriptor = {}; + for ( var i = 0; i < descriptors.length; i++) { + descriptor[descriptors[i][0]] = descriptors[i][1]; + } + + jsTest.log("Trying 2dsphere index with descriptor " + tojson(descriptor)); + + coll.drop(); + coll.ensureIndex(descriptor); + + coll.insert(docA); + coll.insert(docB); + + assert.eq(1, coll.count(Object.merge(query, {field1 : "a"}))); + assert.eq(1, coll.count(Object.merge(query, {field1 : "b"}))); + assert.eq(2, coll.count(Object.merge(query, {field2 : 1}))); + assert.eq(0, coll.count(Object.merge(query, {field2 : 0}))); + + var firstEls = descriptors.splice(1); + descriptors = firstEls.concat(descriptors); +} + +// +// Data taken from previously-hanging result +// + +jsTest.log("Trying case found in wild..."); + +coll.drop(); +coll.ensureIndex({coordinates : "2dsphere", field : -1}); +coll.insert({coordinates : [-118.240013, 34.073893]}); +var query = {coordinates : {$geoWithin : {$centerSphere : [[-118.240013, 34.073893], + 0.44915760491198753]}}, + field : 1}; + +assert.eq(null, coll.findOne(query)); +coll.remove({}) +coll.insert({coordinates : [-118.240013, 34.073893], field : 1}); +assert.neq(null, coll.findOne(query)); + +jsTest.log("Success!"); |