MondoDB, export to CSV with "join" by value

So, I know that the command to export via Mongo shells is

mongoexport --host localhost --db dbname --collection name --csv > test.csv

      

but I also need to do a "join" (in quotes because I know Mongo doesn't actually do so to speak. "I haven't found any documentation on this in the mongo shell.)

I have collections called by users and another one called details. I want to export: users (name, email) and data (city, country) where users (location [object id]) = details (_id [object id]).

The tables look like this:

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") |
+----+-------+---------------+-----------------------+

      

And the result I am trying to achieve is this:

+----+------+---------------+-------+---------------+
| 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 |
+----+------+---------------+-------+---------------+

      

+3


source to share





All Articles