Mongoimport did not import the object correctly

advertisements

In Mongodb v2.2 When I try to import one simple json document file like this from my .json file into an empty collection I get 13 objects imported. Here is what I'm doing.

this is the data (I've shortened the field names to protect data):

[
{
    "date" : ISODate("2012-08-01T00:00:00Z"),
    "start" : ISODate("2012-08-01T00:00:00Z"),
    "xxx" : 1,
    "yyt" : 5,
    "p" : 6,
    "aam" : 20,
    "dame" : "denon",
    "33" : 10,
    "xxt" : 8,
    "col" : 3,
    "rr" : [
        { "name" : "Plugin 1", "count" : 1 },
        { "name" : "Plugin 2", "count" : 1 },
        { "name" : "Plugin 3", "count" : 1 }
    ],
    "xkx" : { "y" : 0, "n" : 1 },
    "r" : { "y" : 0, "n" : 1 },
    "po" : { "y" : 0, "n" : 1 },
    "pge" : { "posts" : 0, "pages" : 1 },
    "pol" : { "y" : 0, "n" : 1 },
    "lic" : { "y" : 0, "n" : 1 },
    "count" : 30,
    "tx" : [
        { "zone" : -7, "count" : 1 }
    ],
    "yp" : "daily",
    "ons" : [
        { "version" : "9.6.8", "count" : 1 }
    ],
    "ions" : [
        { "version" : "10.0.3", "count" : 1 }
    ]
}
]

with this command:

mongoimport --db development_report --collection xxx --username xxx --password xxx --file /Users/Alex/Desktop/daily2.json --type json --jsonArray --stopOnError --journal

I get this weired response:

Mon Sep  3 12:09:12 imported 13 objects

and this 13 new documents end up in the collection instead of one:

{ "_id" : ObjectId("5044114815e24c08bcdc988e") }
{ "_id" : ObjectId("5044114815e24c08bcdc988f"), "name" : "Plugin 1", "count" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9890"), "name" : "Plugin 2", "count" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9891"), "name" : "Plugin 3", "count" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9892"), "y" : 0, "n" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9893"), "y" : 0, "n" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9894"), "y" : 0, "n" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9895"), "posts" : 0, "pages" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9896"), "y" : 0, "n" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9897"), "y" : 0, "n" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9898"), "zone" : -7, "count" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc9899"), "version" : "9.6.8", "count" : 1 }
{ "_id" : ObjectId("5044114815e24c08bcdc989a"), "version" : "10.0.3", "count" : 1 }

What am I doing wrong?


This is really late, but in case it can help anyone else - you should not be passing a JSON array. Simply list 1 JSON document per line, and each line will create a separate document. The file below would insert 2 documents:

{ "date" : { "$date": 1354320000000 }, "xxx" : 1, "yyt" : 5, ... }
{ "date" : { "$date": 1354320000000 }, "xxx" : 2, "yyt" : 6, ... }