summaryrefslogtreecommitdiff
path: root/jstests/core/index_partial_2dsphere.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/index_partial_2dsphere.js')
-rw-r--r--jstests/core/index_partial_2dsphere.js99
1 files changed, 48 insertions, 51 deletions
diff --git a/jstests/core/index_partial_2dsphere.js b/jstests/core/index_partial_2dsphere.js
index 502f70aa556..15e6427667a 100644
--- a/jstests/core/index_partial_2dsphere.js
+++ b/jstests/core/index_partial_2dsphere.js
@@ -4,67 +4,64 @@
(function() {
- "use strict";
+"use strict";
- let coll = db.index_partial_2dsphere;
- coll.drop();
+let coll = db.index_partial_2dsphere;
+coll.drop();
- // Create a 2dsphere partial index for documents where isIndexed is greater than 0.
- let partialIndex = {geoJson: '2dsphere'};
- assert.commandWorked(
- coll.createIndex(partialIndex, {partialFilterExpression: {isIndexed: {$gt: 0}}}));
+// Create a 2dsphere partial index for documents where isIndexed is greater than 0.
+let partialIndex = {geoJson: '2dsphere'};
+assert.commandWorked(
+ coll.createIndex(partialIndex, {partialFilterExpression: {isIndexed: {$gt: 0}}}));
- // This document has an invalid geoJSON format (duplicated points), but will not be indexed.
- let unindexedDoc = {
- "_id": 0,
- "isIndexed": -1,
- "geoJson": {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [0, 1], [0, 0]]]}
- };
+// This document has an invalid geoJSON format (duplicated points), but will not be indexed.
+let unindexedDoc = {
+ "_id": 0,
+ "isIndexed": -1,
+ "geoJson": {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [0, 1], [0, 0]]]}
+};
- // This document has valid geoJson, and will be indexed.
- let indexedDoc = {
- "_id": 1,
- "isIndexed": 1,
- "geoJson": {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]}
- };
+// This document has valid geoJson, and will be indexed.
+let indexedDoc = {
+ "_id": 1,
+ "isIndexed": 1,
+ "geoJson": {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]}
+};
- assert.writeOK(coll.insert(unindexedDoc));
- assert.writeOK(coll.insert(indexedDoc));
+assert.writeOK(coll.insert(unindexedDoc));
+assert.writeOK(coll.insert(indexedDoc));
- // Return the one indexed document.
- assert.eq(1,
- coll.find({
- isIndexed: 1,
- geoJson: {$geoNear: {$geometry: {type: "Point", coordinates: [0, 0]}}}
- })
- .itcount());
+// Return the one indexed document.
+assert.eq(
+ 1,
+ coll.find(
+ {isIndexed: 1, geoJson: {$geoNear: {$geometry: {type: "Point", coordinates: [0, 0]}}}})
+ .itcount());
- // Don't let an update to a document with an invalid geoJson succeed.
- assert.writeError(coll.update({_id: 0}, {$set: {isIndexed: 1}}));
+// Don't let an update to a document with an invalid geoJson succeed.
+assert.writeError(coll.update({_id: 0}, {$set: {isIndexed: 1}}));
- // Update the indexed document to remove it from the index.
- assert.writeOK(coll.update({_id: 1}, {$set: {isIndexed: -1}}));
+// Update the indexed document to remove it from the index.
+assert.writeOK(coll.update({_id: 1}, {$set: {isIndexed: -1}}));
- // This query should now return zero documents.
- assert.eq(0,
- coll.find({
- isIndexed: 1,
- geoJson: {$geoNear: {$geometry: {type: "Point", coordinates: [0, 0]}}}
- })
- .itcount());
+// This query should now return zero documents.
+assert.eq(
+ 0,
+ coll.find(
+ {isIndexed: 1, geoJson: {$geoNear: {$geometry: {type: "Point", coordinates: [0, 0]}}}})
+ .itcount());
- // Re-index the document.
- assert.writeOK(coll.update({_id: 1}, {$set: {isIndexed: 1}}));
+// Re-index the document.
+assert.writeOK(coll.update({_id: 1}, {$set: {isIndexed: 1}}));
- // Remove both should succeed without error.
- assert.writeOK(coll.remove({_id: 0}));
- assert.writeOK(coll.remove({_id: 1}));
+// Remove both should succeed without error.
+assert.writeOK(coll.remove({_id: 0}));
+assert.writeOK(coll.remove({_id: 1}));
- assert.eq(0,
- coll.find({
- isIndexed: 1,
- geoJson: {$geoNear: {$geometry: {type: "Point", coordinates: [0, 0]}}}
- })
- .itcount());
- assert.commandWorked(coll.dropIndex(partialIndex));
+assert.eq(
+ 0,
+ coll.find(
+ {isIndexed: 1, geoJson: {$geoNear: {$geometry: {type: "Point", coordinates: [0, 0]}}}})
+ .itcount());
+assert.commandWorked(coll.dropIndex(partialIndex));
})();