所以我知道通过Mongo shell导出的命令是
mongoexport --host localhost --db dbname --collection name --csv > test.csv
但我还需要做一个"加入" (在引号中,因为我知道Mongo实际上并没有加入,所以说#34;。我还没有找到关于在mongo shell中执行此操作的文档。
我有称为用户的集合和另一个称为详细信息的集合。 我想导出:用户(姓名,电子邮件)和用户(放置[对象ID])=详细信息(_id [对象ID])的详细信息(城市,国家/地区)。
表格如下:
users
+----+------+---------------+-----------------------+
| id | name | email | place |
+----+------+---------------+-----------------------+
| 1 | bob | bob@bob.com | ObjectId("123456abc") |
| 2 | mark | mark@mark.com | ObjectId("654321abc") |
| 3 | dave | dave@dave.com | ObjectId("987655abc") |
+----+------+---------------+-----------------------+
details
+----+-------+---------------+-----------------------+
| id | city | country | _id |
+----+-------+---------------+-----------------------+
| 1 | Perth | Australia | ObjectId("123456abc") |
| 2 | Tokyo | Japan | ObjectId("654321abc") |
| 3 | NY | United States | ObjectId("987655abc") |
+----+-------+---------------+-----------------------+
我试图实现的结果是:
+----+------+---------------+-------+---------------+
| id | name | email | city | country |
+----+------+---------------+-------+---------------+
| 1 | bob | bob@bob.com | Perth | Australia |
| 2 | mark | mark@mark.com | Tokyo | Japan |
| 3 | dave | dave@dave.com | NY | United States |
+----+------+---------------+-------+---------------+