user3559051
user3559051

Reputation: 73

How to create GeoJSON object using Java driver in Mongo DB

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.

Upvotes: 1

Views: 1755

Answers (2)

Sambhav Sharma
Sambhav Sharma

Reputation: 5860

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.

Upvotes: 1

mttdbrd
mttdbrd

Reputation: 1831

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.

Upvotes: 1

Related Questions