Repository navigation
Description
New Issue Checklist
- Report security issues confidentially.
- Any contribution is under this license.
- Before posting search existing issues.
Issue Description
With the MongoDB adapter, query constraints on a regular field go through transformConstraint in src/Adapters/Storage/Mongo/MongoTransform.js, which only accepts the operators of the Parse query language and rejects anything else with error 107 bad constraint: <operator> (for example $not or $elemMatch).
Constraints on a few keys skip that step. transformQueryKeyValue returns the client value untouched for objectId (mapped to _id), sessionToken (mapped to _session_token), _rperm and _wperm, and for authData.<provider>.<field> on _User (mapped to _auth_data_<provider>.<field>). Whatever operator document the client sends under these keys is forwarded to MongoDB as-is, so MongoDB operators that Parse Server does not expose, and arbitrary nesting of them, are evaluated by the database for these keys only.
Examples that MongoDB accepts and evaluates (verified on MongoDB 8.0.23 with a two-document collection):
{"objectId":{"$not":{"$not":{"$regex":"^a"}}}} -> _id:{$not:{$not:{$regex:"^a"}}}
{"_wperm":{"$elemMatch":{"$not":{"$regex":"^z"}}}} -> _wperm:{$elemMatch:{$not:{$regex:"^z"}}}
{"_wperm":{"$all":[{"$elemMatch":{"$regex":"^a"}}]}} -> forwarded verbatim
The same shapes on a regular field are rejected with 107 bad constraint: $not / bad constraint: $elemMatch. Related to this, reduceInRelation (src/Controllers/DatabaseController.js, relatedIds = query[key]['$in'].map(r => r.objectId)) reads pointer object ids from the client without a type check and queries the join table through owningIds before validateQuery runs; a non-string id is rejected by both adapters' $in handling for String fields (107 bad atom on MongoDB, 102 type mismatch on Postgres), so this part only produces a confusing error rather than reaching the database.
Steps to reproduce
Start Parse Server with MongoDB, create any object, then:
curl -s -G http://localhost:1337/parse/classes/TestObject -H 'X-Parse-Application-Id: APP_ID' \
--data-urlencode 'where={"objectId":{"$not":{"$not":{"$regex":"^a"}}}}'
# same operator shape on a regular field
curl -s -G http://localhost:1337/parse/classes/TestObject -H 'X-Parse-Application-Id: APP_ID' \
--data-urlencode 'where={"name":{"$not":{"$not":{"$regex":"^a"}}}}'Actual Outcome
The first query runs on MongoDB and returns the objects whose id starts with a; the second is rejected with {"code":107,"error":"bad constraint: $not"}.
Expected Outcome
Constraints on objectId, sessionToken, _rperm, _wperm and authData.* accept the same operators as any other field and reject unsupported operator documents with the same 107 error, for example by running them through transformConstraint (with the existing special handling for _GlobalConfig/_GraphQLConfig numeric ids and the authData key mapping) instead of returning the raw value. Optionally, reduceInRelation validates that pointer object ids are strings before querying the join table, as reduceRelationKeys already does for $relatedTo.
Environment
Server
- Parse Server version:
9.11.1-alpha.2 - Operating system: macOS 27.0.1
- Local or remote host: local
Database
- System (MongoDB or Postgres): MongoDB (Postgres not checked)
- Database version:
8.0.23 - Local or remote host: local
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc): REST API (
curl) - SDK version: n/a
Logs
n/a
Activity
parse-github-assistant commentedon Nov 5, 2026
🚀 Thanks for opening this issue!
ℹ️ You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
Mani7527 commentedon Nov 23, 2026
Hi! I'd like to work on this. I confirmed it still reproduces on current
alpha:transformQueryKeyValueinMongoTransform.jsreturns the raw client value forobjectId,sessionToken,_rperm,_wpermandauthData.*.My plan:
$not/$elemMatchoperator documents on these keys are rejected with 107bad constraint, the same as on a regular fieldtransformConstraint, keeping the existing_GlobalConfig/_GraphQLConfignumeric id handling and theauthDatakey mapping$in,$nin,$exists,$eq,$ne,$regex, ...) and the internal ACL queries on_rperm/_wpermkeep workingI'll keep the optional
reduceInRelationtype check out of this PR to keep it small, unless you'd prefer it included.