3

I need to export data from MongoDB, however I have run into a problem which I have no idea how to solve.

I know that mongoexport can be used for that, however the problem I'm having is with the database itself.

Let's say there are two collections:

1. "Products" with fields
id (ObjectID)
UserID
SKU
Title

2. "Bullet points" with fields
id (ObjectID)
item (ObjectID from "Products" collection)
content

I need to create a spreadsheet containing the SKU and Title from the "Products" collection AND the "content" of each bullet point for a given batch of SKUs. Obviously there are multiple bullet points per ObjectID.

I've seen plenty of guides on how to export data from MongoDB, but I've never seen a way to do that with multiple collections. Is such a thing possible or do I have to export Products and Bullet points and then match them via Excel?

Please excuse the vague description, I'm familiar with MySQL but pretty new to Mongo.

EDIT: I also cannot run any edit operations on the database, I only have read-only rights.

Khasim
  • 31
  • 1
  • 4

1 Answers1

0

you can export the required fields from different collections and then append the files into one

first : mongoexport --host localhost --db dbname --collection collectionname --csv --out optputFileName.csv --fields SKU Title etc

then you can merge them. take a look at this Merge multiple csv files using batch file.

hope this helps

Community
  • 1
  • 1
techie95
  • 515
  • 3
  • 16