Skip to content

Commit

Permalink
Add test to combine $geoWithin with count_documents
Browse files Browse the repository at this point in the history
Since `$near` doesn't seem to work with it
e-mission/op-admin-dashboard#61 (comment)

```
pymongo.errors.OperationFailure: $geoNear, $near, and $nearSphere are not allowed in this context, full error: {'ok': 0.0, 'errmsg': '$geoNear, $near, and $nearSphere are not allowed in this context', 'code': 2, 'codeName': 'BadValue'}
```

`$geoWithin` seems to be fine. test passes
  • Loading branch information
shankari committed Aug 27, 2023
1 parent a8c7dad commit b6d90cf
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions emission/tests/storageTests/TestMongoGeoJSONQueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ def testGeoWithinPostsData(self):
self.assertEqual(retVal[0]['text'], "My first blog post!")
self.assertEqual(retVal[0]['loc']['coordinates'], [100,32])

def testGeoWithinCounts(self):
post1 = {"author": "Mike",
"text": "My first blog post!",
"tags": ["mongodb", "python", "pymongo"],
'loc':{'type':'Point', 'coordinates':[100,32]}}
self.Sections.insert_one(post1)
post2 = {"author": "hh",
"text": "My 2 blog post!",
"tags": ["mongodb", "python", "pymongo"],
"loc":{'type':'Point', 'coordinates':[200,30]}}
self.Sections.insert_one(post2)

retVal = []
matching_counts = self.Sections.count_documents({ "loc" : { "$geoWithin" : { "$polygon" :[ [ 90,31 ],[90,40] ,[ 110,40 ],[110,31]] } } })

self.assertEqual(matching_counts, 1)

def getTestPolygon(self):
return [ [ 90.234,-31.0323 ],[95.0343,-45.03453] ,[ 110.02322,-43.3435 ],[100.343423,-33.33423]]

Expand Down

0 comments on commit b6d90cf

Please sign in to comment.