Skip to content

Do not throw error if user provide a pointer like index onMongo - #6923

Merged
davimacedo merged 2 commits into
parse-community:masterfrom
Moumouls:handle-simple-pointer-index
Oct 1, 2020
Merged

Do not throw error if user provide a pointer like index onMongo#6923
davimacedo merged 2 commits into
parse-community:masterfrom
Moumouls:handle-simple-pointer-index

Conversation

@Moumouls

@Moumouls Moumouls commented Oct 1, 2020

Copy link
Copy Markdown
Member

Here a mini fix since an old PR of @dplewis was closed (#4629) to just allow advanced developers to create index for pointers field. I know it's not the best solution, but currently it could be an easy workaround.

@Moumouls

Moumouls commented Oct 1, 2020

Copy link
Copy Markdown
Member Author

Since lint here just add some difficulty to read here the main (little) code:
We just need to avoid throwing an error if the developer try to create a pointer like index

Object.keys(field).forEach(key => {
          if (
            !Object.prototype.hasOwnProperty.call(
              fields,
              key.indexOf('_p_') === 0 ? key.replace('_p_', '') : key
            )
          ) {

@codecov

codecov Bot commented Oct 1, 2020

Copy link
Copy Markdown

Codecov Report

Merging #6923 into master will decrease coverage by 0.04%.
The diff coverage is 72.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6923      +/-   ##
==========================================
- Coverage   93.85%   93.80%   -0.05%     
==========================================
  Files         169      169              
  Lines       12220    12220              
==========================================
- Hits        11469    11463       -6     
- Misses        751      757       +6     
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.92% <72.72%> (-0.67%) ⬇️
src/RestWrite.js 93.82% <0.00%> (-0.33%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.02% <0.00%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 922dc76...b379212. Read the comment docs.

@Moumouls

Moumouls commented Oct 1, 2020

Copy link
Copy Markdown
Member Author

Test case added i don't know why code cov is not happy :/

@davimacedo
davimacedo merged commit 929c4e1 into parse-community:master Oct 1, 2020
nagendertank pushed a commit to nagendertank/parse-server that referenced this pull request Aug 18, 2026
…pdatedAt`, `objectId`, `sessionToken`) declared via the schema API or schema definitions are created on the Parse field name instead of the MongoDB storage key, so queries never use them

The MongoDB adapter stores Pointer fields under `_p_<field>` and several
built-in fields under internal keys (`_created_at`, `_updated_at`, `_id`,
`_session_token`, `_last_used`, `times_used`), and the query transform
rewrites query keys accordingly. `ensureIndex` and `ensureUniqueness`
already translate index keys the same way, but
`setIndexesWithSchemaFormat` - the path behind the schemas REST API and
schema definitions (DefinedSchemas) - created the physical index on the
declared field name verbatim, producing an index that queries can never
use while the schema API reported it as present.

The physical index is now created on the storage key via the same
`transformKey` mapping the query path uses, while `_metadata.indexes`
keeps storing and reporting the declared Parse-format key spec. The
startup index re-sync (`setIndexesFromMongo`) now preserves a declared
key spec when it maps to the same physical index, so schema API
responses stay stable across restarts and schema definitions do not
detect a false difference and rebuild indexes on every boot.

Existing behavior is preserved: declarations that already use storage
keys (e.g. `_p_field`, supported since parse-community#6923) work unchanged, indexes
created outside Parse Server are still discovered and reported with
their raw keys, and pre-existing (non-functional) indexes on existing
deployments are left untouched; deleting and re-adding such an index
through the schema API now yields a working index.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants