导入后 Mongoimport 未将 JSON 文档添加到数据库
Mongoimport not adding JSON documents to db after import
mongoimport 命令 returns 使用正确数量的文档,并添加了一个新集合,但是当我尝试打开我的数据库时,什么也没有。我正在使用 json 数组来存储我的数据,但不确定为什么这不起作用。
C:\Program Files\MongoDB\Server.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.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" ]
我的 data.json 文件是。
[{"name":"A.J. Green","team":"CIN","pos":"WR","weeklyPts":[{"week":1,"pts":6.3},{"week":2,"pts":10.5},{"week":3,"pts":34.7}]}]
您的 find() 中的集合名称错误,您正在对 playerList 集合进行查找,但您将数据导入到名为 "data" 的集合中。所以尝试:
db.data.find().pretty()
你的 collection 是数据而不是 playerList 可以在最后一行查看,即 db.getCollectionNames()
,将 db.playerList.find().pretty
更改为 db.data.find.pretty()
它会起作用
mongoimport 命令 returns 使用正确数量的文档,并添加了一个新集合,但是当我尝试打开我的数据库时,什么也没有。我正在使用 json 数组来存储我的数据,但不确定为什么这不起作用。
C:\Program Files\MongoDB\Server.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.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" ]
我的 data.json 文件是。
[{"name":"A.J. Green","team":"CIN","pos":"WR","weeklyPts":[{"week":1,"pts":6.3},{"week":2,"pts":10.5},{"week":3,"pts":34.7}]}]
您的 find() 中的集合名称错误,您正在对 playerList 集合进行查找,但您将数据导入到名为 "data" 的集合中。所以尝试:
db.data.find().pretty()
你的 collection 是数据而不是 playerList 可以在最后一行查看,即 db.getCollectionNames()
,将 db.playerList.find().pretty
更改为 db.data.find.pretty()
它会起作用