将json文件导入mongo的正确方法 [英] Proper way to import json file to mongo
问题描述
我一直在尝试对导入的某些数据使用mongo,但是我无法在我的文档说明中正确使用它.
I've been trying to use mongo with some data imported, but I'm not able to use it properly with my document description.
这是我使用mongoimport导入的.json的示例: https://gist.github.com/2917854
This is an example of the .json I import using mongoimport: https://gist.github.com/2917854
mongoimport -d test -c example data.json
我注意到,尽管为每个商店都创建了一个对象,但是我将所有文档都导入了一个唯一的对象.
I noticed that all my document it's imported to a unique object in spite of creating one of object for each shop.
这就是为什么当我尝试寻找商店或任何我想查询的东西时,所有文档都被退回了的原因.
That's why when I try to find a shop or anything I want to query, all the document is returned.
db.example.find({"shops.name":"x"})
我希望能够使用类似于以下内容的点符号查询数据库以获取ID的产品:
I want to be able to query the db to obtain products by the id using dot notation something similar to:
db.example.find({"shops.name":"x","categories.type":"shirts","clothes.id":"1"}
问题在于所有文档都像单个对象一样被导入.问题是:如何
我需要导入对象以获得我想要的结果吗?
The problem is that all the document is imported like a single object. The question is: How
do I need to import the object to obtain my desired result?