Best practice to transform JSON with MongoDB

Skip to first unread message

D Boyd

Nov 1, 2010, 7:39:46 PM11/1/10
to mongodb-user
Greetings all:
I am pretty new to Mongo and had a question I hope the group can
help with.

I have a number of records in the DB now, that I would like to
transform server side from their
current structure into a GeoJSON compliant structure.
Basically, the records are of the form:

{ id: "id1", att1: "att value", att2: "att 2 value", lat: "34.33",
lon: "22.34" }

I need to transform that into GeoJSON of the form:

{ "type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
[22.34, 34.33]
"properties": {
"att1": "att value",
"att2": "att 2 value"

In my searches I found a couple of interesting Javascript functions
(jsonT, jsonPath) at

I have successfully stored them inside my mongo instance and was even
able from the console to execute jsonPath on a result set.
However the whole syntax with db.eval is klunky and I have read about
issues with
it blocking the database.

There are several brute force approaches that can be written in
javascript or java to do the work but
before I tackled those I thought I would ask the list if there was
some best practice or more elegant

Kyle Banker

Nov 3, 2010, 10:33:47 AM11/3/10
I think that the fastest and best approach here would be to query your
collection in batches, transform using Java, and then bulk-insert into
a new collection.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to
> To unsubscribe from this group, send email to
> For more options, visit this group at

Reply all
Reply to author
0 new messages