Home:ALL Converter>How to merge 10 collections (with the same structure) into a single collection?

How to merge 10 collections (with the same structure) into a single collection?

Ask Time:2021-09-06T17:44:34         Author:cauchuyennhocuatoi

Json Formatter

I have 10 collections (with the names user_01, user_02, ... user_10). These 10 collections all have the same structure (I import from CSV file into MongoDB). Because the data of each CSV file is too big I have to split into 10 different files (data_01.csv, data_02.csv, ... data_10.csv) when importing into MongoDB (I put in 10 different collections as above, not a single collection).

But now I need to merge these 10 collections into a single collection called "user" to query data. Is there any way to migrate data from these 10 collections into a single collection called "user"?

The structure of each collection :

{
    "_id" : ObjectId("6119cac0fe31d614997b07f0"),
    "name": "Robert"
    "address" : "36 rue Nationale, Paris, France",
    "sex" : "female",
    "age" : 45,
    "account_activated_date" : 19990101
}

Author:cauchuyennhocuatoi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69072453/how-to-merge-10-collections-with-the-same-structure-into-a-single-collection
yy