tags:

views:

56

answers:

1

Trying to use the built in mongoimport utility with mongo db...

I might be blind but is there a way to import complex json data? For instance, say I need to import instances of the following object: { "bob": 1, "dog": [ 1, 2, 3 ], "beau": { "won": "ton", "lose": 3 } }.

I'm trying the following and it looks like it loads everything into memory but nothing actually gets imported into the db:

$ mongoimport -d test -c testdata -vvvv -file ~/Downloads/jsondata.json connected to: 127.0.0.1 Tue Aug 10 17:38:38 ns: test.testdata Tue Aug 10 17:38:38 filesize: 69 Tue Aug 10 17:38:38 got line:{ "bob": 1, "dog": [ 1, 2, 3 ], "beau": { "won": "ton", "lose": 3 } } imported 0 objects

Any ideas on how to get the json data to actually import into the db?

A: 

I did some testing and it looks like you need to have an end-of-line character at the end of the file. Without the end-of-line character the last line is read, but isn't imported.

Niels van der Rest
That was it! Thank you so much!
longda