JSON Serialization and Near Query Distance Maximum Distance Limit

63 views
Skip to first unread message

Andrew Brown

unread,
Apr 9, 2011, 12:49:39 AM4/9/11
to MongoEngine Users
I apologize if this is a duplicate post. I tried to email this group
earlier today, but I think it failed because I wasn't a member yet.

Anyway, I have to questions about mongoengine. First, I'm using
mongoengine with django and I'm trying to return the results of some
queries in JSON format. Is there a standard way for serializing
mongoengine QuerySets as JSON? I found this post on the topic from
over a year ago, but I want to check and see if it is still the best
way. http://groups.google.com/group/mongoengine-dev/browse_thread/thread/d740fe1fd8aa8a5f

Second, does mongoengine support specifying a maximum distance for
"near" queries? For example I want to do this query:

Place.objects(location__near=[lat, lng]).limit(20)

but I only want results within 1 degree of the specified location,
even if that is less than the limit of 20.

If that's not built in to mongoengine I'll just use the __raw__
option, but figured I would check first.

Thanks,
Andrew

chuquizutta

unread,
Apr 9, 2011, 7:43:27 PM4/9/11
to mongoeng...@googlegroups.com
I'm really new to mongoengine (I was reading the docs yesterday) and maybe you are looking for the within* (copy and pase from docs):

There are a few special operators for performing geographical queries, that may used with GeoPointFields:

  • within_distance – provide a list containing a point and a maximum distance (e.g. [(41.342, -87.653), 5])
  • within_box – filter documents to those within a given bounding box (e.g. [(35.0, -125.0), (40.0, -100.0)])
  • near – order the documents by how close they are to a given point
About JSON, I can't help you (yet)..

Regards
Hope it help

MonTarO

unread,
Apr 10, 2011, 4:47:46 AM4/10/11
to mongoeng...@googlegroups.com
will that help ? :

Person.objects(name='ahmed')._query
>>> {'_types': 'Person', 'name': 'ahmed'}
Reply all
Reply to author
Forward
0 new messages