尝试导入包含联系信息的 CSV:
Name,Address,City,State,ZIP Jane Doe,123 Main St,Whereverville,CA,90210 John Doe,555 Broadway Ave,New York,NY,10010
运行它似乎不会将任何文档添加到数据库中:
$ mongoimport -d mydb -c things --type csv --file locations.csv --headerline
Trace 说imported 1 objects,但是启动 Mongo shell 并运行db.things.find()并没有显示任何新文档。
imported 1 objects
db.things.find()
我错过了什么?
您的示例适用于 MongoDB 1.6.3 和 1.7.3。以下示例适用于 1.7.3。您使用的是旧版本的 MongoDB 吗?
$ cat > locations.csv Name,Address,City,State,ZIP Jane Doe,123 Main St,Whereverville,CA,90210 John Doe,555 Broadway Ave,New York,NY,10010 ctrl-d $ mongoimport -d mydb -c things --type csv --file locations.csv --headerline connected to: 127.0.0.1 imported 3 objects $ mongo MongoDB shell version: 1.7.3 connecting to: test > use mydb switched to db mydb > db.things.find() { "_id" : ObjectId("4d32a36ed63d057130c08fca"), "Name" : "Jane Doe", "Address" : "123 Main St", "City" : "Whereverville", "State" : "CA", "ZIP" : 90210 } { "_id" : ObjectId("4d32a36ed63d057130c08fcb"), "Name" : "John Doe", "Address" : "555 Broadway Ave", "City" : "New York", "State" : "NY", "ZIP" : 10010 }