Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use $near #54

Open
martinsJoseph opened this issue Jan 15, 2019 · 0 comments
Open

Unable to use $near #54

martinsJoseph opened this issue Jan 15, 2019 · 0 comments

Comments

@martinsJoseph
Copy link

Hello guys,
I am having issues with using flask-mongoalchemy to query my database and get results that are close to the longitude and latitude I passed.

My Model:

class Event(db.Document):
meta = {
'indexes': [
("*location.coordinates", "2dsphere")
]
}

user_id = db.StringField()
uuid = db.StringField()
name = db.StringField()
address = db.StringField()
start_time = db.DateTimeField(required=True, default=datetime.datetime.now())
end_time = db.DateTimeField(required=True, default=datetime.datetime.now())
location = db.DictField(db.AnythingField())

When an event is created this is how the document is meant to look like:
{
"address": "Surulere",
"end_time": "2019-10-13T00:00:00",
"location": {
"coordinates": [
-119.3996898,
19.6255545
],
"type": "Point"
},
"name": "Amazonss__",
"start_time": "2019-10-12T00:00:00",
"user_id": "3b15b5f9d6d1ab93d14db52cabe6ac",
"uuid": "baa75b69047369a48342e6939c56d3"
}

And My Code for Querying is:
event = Event.query.filter({"location" :
{ "$near" :
{
"$geometry" : {
"type" : "Point",
"coordinates" : [longitude, latitude] },
"$maxDistance" : 4000
}
}
}).first()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant