parse-community / parse-community/parse-server

DefinedSchema: Indexes not created correctly for Pointer types

Open
#8,455 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

New Issue Checklist

/cc @Moumouls

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
Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing DefinedSchema's index creation from the SchemaMigrations example and compare its field name with Parse's MongoDB Pointer storage convention. Reproduce the shown stats output, then verify that a Pointer index is created on _p_recipient rather than recipient.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, nodejs
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.