How to add index on createdAt and updatedAt if possible?

We are having this failure when sort using createdAt on MongoDB
“Executor error during find command :: caused by :: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.”,

We tried to add an index to createdAt by post to /schemas/${className}

    indexes: {
            _createdAt_: {
                createdAt: 1
            },
            _updatedAt_: {
                updatedAt: 1
            }
        }

The post worked. Looking at the MongoDB it seems the indexes are created but on MongoDB it is _created_at and _updated_at. So the query above still fail

We tried to post the following but the post fails

    indexes: {
            _created_at_: {
                _created_at: 1
            },
            _updated_at_: {
                _updated_at: 1
            }
        }

Thank you in advance!

Try using mongo shell:

db.getCollection('ClassName').createIndex({ _created_at: 1 })
db.getCollection('ClassName').createIndex({ _updated_at: 1 })

Thank you @davimacedo, I’ll try that. But what is going on with the endpoint to create the index? Is that a bug?

I believe it should work with:

indexes: {
            _created_at_: {
                _created_at: 1
            },
            _updated_at_: {
                _updated_at: 1
            }
        }

What is the error message that you get?

{
“code”: 102,
“error”: “Field _created_at does not exist, cannot add index.”
}

In this case, I believe that the right request should be with createdAt (your first version) but Parse Server should convert the field name to the MongoDB version. I believe there is a bug here. Do you mind to open an issue in the repo?

Gladly! https://github.com/parse-community/parse-server/issues/6834

1 Like