user3610275 user3610275 - 1 year ago 106
JSON Question

Mongoimport not adding JSON documents to db after import

mongoimport command returns with the correct amount of documents, and adds a new collection but when I try to open my db there is nothing. I am using a json array to store my data but am not sure why this isnt working.

C:\Program Files\MongoDB\Server\3.2\bin>mongoimport --db playerList --collection data --jsonArray --file ../../../../../nodeProjects/public/data.json
2016-07-20T09:30:05.807-0700 connected to: localhost
2016-07-20T09:30:05.813-0700 imported 1 document

C:\Program Files\MongoDB\Server\3.2\bin>mongo
MongoDB shell version: 3.2.7
connecting to: test
> use playerList
switched to db playerList
> db.playerList.find().pretty()
> db.getCollectionNames()
[ "data" ]

and my data.json file is.

[{"name":"A.J. Green","team":"CIN","pos":"WR","weeklyPts":[{"week":1,"pts":6.3},{"week":2,"pts":10.5},{"week":3,"pts":34.7}]}]

Answer Source

your collection is data not playerList which can be viewed in last line i.e db.getCollectionNames(), change db.playerList.find().pretty to it will work

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download