parse-server
parse-server copied to clipboard
DefinedSchema: Indexes not created correctly for Pointer types
New Issue Checklist
/cc @Moumouls
- [x] I am not disclosing a vulnerability.
- [x] I am not just asking a question.
- [x] I have searched through existing issues.
- [x] I can reproduce the issue with the latest version of Parse Server.
Issue Description
When creating indexes on Pointer fields, the index is not created on the correct field name in MongoDB
Parse will add a _p_ prefix to the field name, but DefinedSchema won't. This have for consequence to leave the Pointer field without an index, and creating an index on a non-existant field.
Had a chat with @Moumouls about this, here is his comment:
The correct version indeed is the version with the
_p_, it is a quick fix that was pushed during the pr of the defined schemas. I remember it needed some refactor to allow just the field name without the p because of validators.
Steps to reproduce
For example:
export default SchemaMigrations.makeSchema('Message', {
fields: {
recipient: { type: 'Pointer', targetClass: '_User', required: true },
},
indexes: {
recipient: { recipient: 1 },
},
Looking at the indexes:
db.getCollection('Message').stats()
{
"_id_": new NumberInt("749568"),
"recipient": new NumberInt("90112"),
}
In this case, Parse will create a DB field named _p_recipient, not recipient.
This have for effect of leaving the _p_recipient un-indexed, and creating an unused index recipient
Actual Outcome
Index is created on unused field recipient
Expected Outcome
Index need to be created on _p_recipient
Environment
Server
- Parse Server version:
5 - Operating system:
w11 - Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
gcloud
Database
- System (MongoDB or Postgres):
MongoDB - Database version:
4.4 - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
gcloud
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
javascript - SDK version:
4