summaryrefslogtreecommitdiff
path: root/jstests/core/geo_haystack3.js
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2014-01-14 14:09:42 -0500
committerRandolph Tan <randolph@10gen.com>2014-02-28 16:26:33 -0500
commit5595b945603b0712c537787e31e6da661c424fee (patch)
tree90945ee3fe4931032f3af2d397bb755fbf5d30ef /jstests/core/geo_haystack3.js
parentcd62080dcb036e83f8fca6d68d9bcab67bf7a21c (diff)
downloadmongo-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_haystack3.js')
-rw-r--r--jstests/core/geo_haystack3.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/jstests/core/geo_haystack3.js b/jstests/core/geo_haystack3.js
new file mode 100644
index 00000000000..f5a2ab7becb
--- /dev/null
+++ b/jstests/core/geo_haystack3.js
@@ -0,0 +1,28 @@
+t = db.geo_haystack3
+t.drop()
+
+t.insert({ pos : { long : 34, lat : 33 }})
+t.insert({ pos : { long : 34.2, lat : 33.3 }, type : ["bar", "restaurant" ]})
+t.insert({ pos : { long : 34.2, lat : 37.3 }, type : ["bar", "chicken" ]})
+t.insert({ pos : { long : 59.1, lat : 87.2 }, type : ["baz", "office" ]})
+t.ensureIndex({ pos : "geoHaystack", type : 1 }, { bucketSize : 1 })
+
+// This only matches the first insert. What do we want? First 3 or just the first?
+res = t.runCommand("geoSearch", { near : [33, 33], maxDistance : 6, search : {}, limit : 30 })
+assert.eq(1, res.stats.n, "Right # of matches");
+assert.eq(34, res.results[0].pos.long, "expected longitude");
+assert.eq(33, res.results[0].pos.lat, "expected latitude");
+
+// This matches the middle 2 of the 4 elements above.
+res = t.runCommand("geoSearch", { near : [33, 33], maxDistance : 6, search : { type : "bar" },
+ limit : 2 })
+assert.eq(2, res.stats.n, "Right # of matches");
+assert.eq("bar", res.results[0].type[0], "expected value for type");
+assert.eq("bar", res.results[1].type[0], "expected value for type");
+assert.neq(res.results[0].type[1], res.results[1].type[1], "should get 2 diff results");
+
+// This is a test for the limit being reached/only 1 returned.
+res = t.runCommand("geoSearch", { near : [33, 33], maxDistance : 6, search : { type : "bar" },
+ limit : 1 })
+assert.eq(1, res.stats.n, "Right # of matches");
+assert.eq("bar", res.results[0].type[0], "expected value for type");