MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_index_2dsphere

Method test_index_2dsphere

test/test_collection.py:501–518  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

499 db.test.drop_indexes()
500
501 def test_index_2dsphere(self):
502 db = self.db
503 db.test.drop_indexes()
504 self.assertEqual("geo_2dsphere", db.test.create_index([("geo", GEOSPHERE)]))
505
506 for dummy, info in (db.test.index_information()).items():
507 field, idx_type = info["key"][0]
508 if field == "geo" and idx_type == "2dsphere":
509 break
510 else:
511 self.fail("2dsphere index not found.")
512
513 poly = {"type": "Polygon", "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]]}
514 query = {"geo": {"$within": {"$geometry": poly}}}
515
516 # This query will error without a 2dsphere index.
517 db.test.find(query)
518 db.test.drop_indexes()
519
520 def test_index_hashed(self):
521 db = self.db

Callers

nothing calls this directly

Calls 5

itemsMethod · 0.80
drop_indexesMethod · 0.45
create_indexMethod · 0.45
index_informationMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected