The reason for the issue I encountered was a difference in the index settings between two MongoDB databases. When copying documents from one database to another, I noticed that the first database had a TTL (time to live) index, while the second database did not have this feature.
$ mongo "mongodb+srv://....database-1-url"
>> db.myschema.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
},
{
"v" : 2,
"key" : {
"paidOn" : 1
},
"name" : "paidOn_1",
"background" : true
}
]
In contrast, the database I was working with had an expireAfterSeconds
index setting.
$ mongo "mongodb+srv://....database-2-url"
>> db.myschema.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
},
{
"v" : 2,
"key" : {
"expireAt" : 1
},
"name" : "expireAt_1",
"background" : true,
"expireAfterSeconds" : 86400
},
{
"v" : 2,
"key" : {
"paidOn" : 1
},
"name" : "paidOn_1",
"background" : true
}
]
This resulted in MongoDB deleting new documents where the expireAt
field contained an old date.
To resolve the issue, I executed await Order.syncIndexes();
in a script, resetting the index setting to
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" } ]
. While this solved my immediate problem, it meant that the index structure differed from the first database as the paidOn key was no longer indexed.
My Initial Misconception
Initially, I attributed the problem to the large size of the jsonDocs
.
Within these objects were fields containing extensive base64 strings for images, placeholders awaiting replacement with HTTP URLs for the images.
Although removing the base64 strings appeared to assist in uploading documents, in reality, it only accelerated the process. MongoDB still required one minute to check for expired documents.