def example(): mongo = yield txmongo.MongoConnection() foo = mongo.foo # `foo` database test = foo.test # `test` collection idx = filter.sort(filter.ASCENDING("something") + filter.DESCENDING("else")) print "IDX:", idx result = yield test.create_index(idx) print "create_index:", result result = yield test.index_information() print "index_information:", result result = yield test.drop_index(idx) print "drop_index:", result # Geohaystack example geoh_idx = filter.sort(filter.GEOHAYSTACK("loc") + filter.ASCENDING("type")) print "IDX:", geoh_idx result = yield test.create_index(geoh_idx, **{'bucketSize':1}) print "index_information:", result result = yield test.drop_index(geoh_idx) print "drop_index:", result # 2D geospatial index geo_idx = filter.sort(filter.GEO2D("pos")) print "IDX:", geo_idx result = yield test.create_index(geo_idx, **{ 'min':-100, 'max':100 }) print "index_information:", result result = yield test.drop_index(geo_idx) print "drop_index:", result
def test_index_geo2d(self): coll = self.coll geo_ix = yield coll.create_index(qf.sort(qf.GEO2D("loc"))) self.assertEqual("loc_2d", geo_ix) index_info = yield coll.index_information() self.assertEqual({"loc": "2d"}, index_info["loc_2d"]["key"])
def test_index_geo2d(self): db = self.db coll = self.coll yield coll.drop_indexes() geo_ix = yield coll.create_index(filter.sort(filter.GEO2D("loc"))) self.assertEqual('loc_2d', geo_ix) index_info = yield coll.index_information() self.assertEqual([('loc', '2d')], index_info['loc_2d'])
def test_SortGeoIndexes(self): self.assertEqual(qf.sort(qf.GEO2D('x')), qf.sort([('x', "2d")])) self.assertEqual(qf.sort(qf.GEO2DSPHERE('x')), qf.sort([('x', "2dsphere")])) self.assertEqual(qf.sort(qf.GEOHAYSTACK('x')), qf.sort([('x', "geoHaystack")]))