Mongoimport of JSON file Mongoimport of JSON file mongodb mongodb

Mongoimport of JSON file


I was able to fix the error using the following query:

mongoimport --db dbName --collection collectionName --file fileName.json --jsonArray

Hopefully this is helpful to someone.


try this,

mongoimport --db dbName --collection collectionName <fileName.json

Example,

mongoimport --db foo --collection myCollections < /Users/file.jsonconnected to: *.*.*.*Sat Mar  2 15:01:08 imported 11 objects

Issue is because of you date format.

I used same JSON with modified date as below and it worked

{jobID:"2597401",account:"XXXXX",user:"YYYYY",pkgT:{"pgi/7.2-5":{libA:["libpgc.so"],flavor:["default"]}},     startEpoch:"1338497979",runTime:"1022",execType:"user:binary",exec:"/share/home/01482/XXXXX/appker/ranger/NPB3.3.1/NPB3.3-MPI/bin/ft.D.64",numNodes:"4",sha1:"5a79879235aa31b6a46e73b43879428e2a175db5",execEpoch:1336766742,execModify:{"$date" : 1343779200000},startTime:{"$date" : 1343779200000},numCores:"64",sizeT:{bss:"1881400168",text:"239574",data:"22504"}}

hope this helps


Using mongoimport you can able to achieve the same

mongoimport --db test --collection user --drop --file ~/downloads/user.json

where,

test - Database nameuser - collection nameuser.json - dataset file

--drop is drop the collection if already exist.