0

Is there any way in Mongodb, to export collection with all fields without adding manually?

In Compass, when I go to export collection I see an example of the fields to export, example:

enter image description here

But if I check each document by hand, I can see that some objects have different fields inside.

Sure, if I add manually all the fields that I need it will exported correctly, but it's impossible to me to know which fields are in a database with 50M of documents where an external API inserts those objects as they want.

Is there any way?

pmiranda
  • 7,602
  • 14
  • 72
  • 155
  • 1
    Try exporting by unchecking all the fields by clicking on "Field Name" checkbox. – turivishal Oct 07 '22 at 10:45
  • Approaching this from another way, what's the goal of the export? Is this a one time task? Where is the data going from and to? There are a variety of other methods to achieve your generally stated goal of exporting a collection with all fields (eg `mongoexport`), but it seems you may be specifically asking about accomplishing a task in Compass? – user20042973 Oct 07 '22 at 13:13
  • @user20042973 One time task. I have to export data from MongoDB to CosmosDB, but CosmosDB has their own indexes, so I can't make a full dump on MongoDB and just put them on CosmosDB, I had to create by hand each index on CosmosDB and now I want to import collection by collection from MongoDB. The solution of the comment above make my day, thanks – pmiranda Oct 07 '22 at 16:48
  • 1
    Great, glad to hear it's resolved! For completeness, there is no tool that I'm aware of that dumps index _data_. Tools like `mongodump` can include index _definitions_ in the output but even then the associated `mongorestore` utility [has an option for skipping index builds during the restore](https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--noIndexRestore). I don't know if any of these utilities are compatible with CosmosDB, but maybe useful information to know in the future – user20042973 Oct 07 '22 at 17:23

0 Answers0