1

I am a newbie in MongoDB. Can anyone tell me how I can create a simple GeoJSON object ? I will be working with GeoSpatial queries hence I need some basic help with creating a GeoJSON object using Java Mongo driver.

2 Answers 2

1

Try the SpringData Mongo driver. It has methods in the Criteria object to create the kind of query you want:

http://docs.spring.io/spring-data/data-mongo/docs/1.4.2.RELEASE/api/index.html?org/springframework/data/mongodb/core/query/Criteria.html

The official Java driver for MongoDB is really not very good. The equivalent JavaScript commands are distributed unevenly across the Java API, and sometimes you're required to do what @Sambhav-Sharma says: just pass MongoDB operators as strings.

Sign up to request clarification or add additional context in comments.

2 Comments

The Mongo doc refers to "legacy coordinate pairs" a lot. Is it not correct to use them with Lat and Long replacing x and y?
The "legacy coordinate pairs" refers to the format of point coordinates before Mongo 2.4. It was a planar system. Mongo now supports spherical and 2d. Legacy is version 1 of the "2dsphere."
1

You cannot create separate GeoJSON objects using Java Driver. You will have to use query builders to produce GeoJSON queries.

Use Basicdb objects and append Geo data to the objects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.