0

I have a json file exported from a mongo collection

[
{
    "_id": {
        "$oid": "53e8a29fe434b85c22000405"
    },
    "registeredOn": "127.0.0.1",
    "password": "5cb67a32022e6df37c6adece17756380",
    "email": "[email protected]",
    "clean": "asdqwe",
    "username": "asdqwe",
    "picture": "default.png",
    "message": "yazarın mottosu",
    "entry_count": 0,
    "point": 0,
    "lastLogin": {
        "$date": "2014-08-11T14:01:51.102+0300"
    },
    "generation": 1,
    "gender": 0,
    "auth": 1,
    "registeredAt": {
        "$date": "2014-08-11T14:01:51.102+0300"
    },
    "__v": 0
},
{
    "_id": {
        "$oid": "53e8a29fe434b85c22000406"
    },
    "registeredOn": "127.0.0.1",
    "password": "7323bac004ed0148c6a3206e0d870ea4",
    "email": "[email protected]",
    "clean": "asdqweqw",
    "username": "asdasdasdo",
    "picture": "default.png",
    "message": "yazarın mottosu",
    "entry_count": 0,
    "point": 0,
    "lastLogin": {
        "$date": "2014-08-11T14:01:51.203+0300"
    },
    "generation": 1,
    "gender": 0,
    "auth": 1,
    "registeredAt": {
        "$date": "2014-08-11T14:01:51.203+0300"
    },
    "__v": 0
}
]

I get an error from mongoimport when I try to import it into my database.

This is the command I used:

mongoimport -d sausozlukdb -c users users.json --jsonArray

result

check 0 0 imported 0 objects ERROR: encountered 1 error(s)

Please help me, thanks in advance.

I noticed a detail , my export file exported from mongodb 2.6 but my target database is mongodb 2.4

6
  • Is that the whole file? Because there is a 16MB limit to imports with the --jsonArray flag. Commented Aug 11, 2014 at 21:14
  • my file only 400kb and 1050line json file. Commented Aug 11, 2014 at 21:19
  • I just copied the file as is into a JSON file and imported it using the command you are using without a problem. It should work fine for you too, unless there are duplicate IDs or your mongod is not running. What does the actual error say? Commented Aug 11, 2014 at 21:22
  • I try on digitalocean console, mongod not running when i writing this codes. is it relate that? Commented Aug 11, 2014 at 21:24
  • 1
    mongod will need to be running for mongoimport to work. Commented Aug 11, 2014 at 21:26

3 Answers 3

2

There have been a number of fixes to mongoimport since MongoDB 2.4 - in particular to improve the robustness of parsing and ensure values can be round-tripped via mongoexport using MongoDB Extended JSON.

Your users.json file is valid, but the 2.4.10 mongoimport definitely doesn't like:

  • UTF characters in the message field
  • $date format

... and possibly more. Since every file tweak seemed to lead to another issue, I did not continue testing.

However, this JSON appears to import fine with the 2.6.4 mongoimport so I would suggest using the newer version instead.

I'm not aware of any issues using 2.6 mongoimport to import into MongoDB 2.4, and it works fine for the example you've provided.

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

1 Comment

that's true, I downgrade my local mongodb version and re-export my database output. My import progress completed successfuly on server now.
0

Try validating the JSON file:

python -mjson.tool < users.json

It will tell you where any errors are.

1 Comment

i validated on jsonlint.com, my json file is valid.
0
    mongoimport --d sausozlukdb -c users users.json --jsonArray

Double hyphon needed.

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.