I have mongodb
collection say collectionA
which have document structure like this:
{
"_id": ObjectId("xyz"),
"username": "XYZ",
"funds": [{doc}, {doc}, ...],
"checkout": {nested doc}
}
I've realized that this will grow a lot. Therefore I want to split all documents in this collection into two as below:
{
"_id": ObjectId("xyz"),
"username": "XYZ",
"funds": [...]
}
&
{
"_id": ObjectId("xyz"),
"username": "XYZ",
"checkout": {nested doc}
}
With ID & username being same for corresponding entries in both collections.
I could find copying complete document from one collection to another via copyTo()
, but what I am looking for is something different. How can I achieve this?
Thanks in advance.