`hint` should be allowed with `distinct`
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, mongodb, nodejs
- Domain
- database
Research direction
The denial lives in lib/permissions.js under denied.distinct.hint, and the JSDoc on Query.prototype.hint() repeats the restriction. Read _validate('hint') to see how the throw is reached, then check that Query.prototype.__distinct forwards hint through _optionsForExec(). Done when Model.distinct(...).hint({ a: 1 }) no longer throws against a 7.1+ server and the permissions test for distinct still passes.
Written by the indexing model from the issue text.
Description
lib/permissions.js lists hint among the options distinct can't take (denied.distinct.hint = true), so Query.prototype.hint() throws hint cannot be used with distinct via _validate('hint'). Mongoose routes every query option through mquery, so Model.distinct(field, filter).hint({ a: 1 }), or setOptions({ hint }) in a pre('distinct') hook, throws on the client before anything reaches the server.
The server's distinct command has accepted hint since MongoDB 7.1 (docs), and the Node driver's DistinctOptions.hint sends it (@sinceServerVersion 7.1). Mongoose's Query.prototype.__distinct already passes hint through _optionsForExec(), so removing the denial is enough.
Repro (mquery 6.0.1 / Mongoose 9.10.3, server 8.0):
await Model.distinct('field', { a: { $in: ids } }).hint({ a: 1 });
// Error: hint cannot be used with distinct
Proposed fix: remove denied.distinct.hint, and drop "Cannot be used with distinct()" from the hint() JSDoc. Servers older than 7.1 reject the field themselves, the same as other version-gated options. Happy to open the PR.
- Dominant language
- JavaScript
- Stars
- 485
- Forks
- 68
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mongoosejs/mquery
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
mongoosejs/mquery#139 ·
-
Typescript supportOpen
Difficulty 4/5 3-5 days Newbie friendliness 20/100
mongoosejs/mquery#119 · 2 comments · 3 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
mongoosejs/mquery#77 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
mongoosejs/mquery#36 ·
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
mongoosejs/mquery#10 ·
All issues in mongoosejs/mquery
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
521xueweihan/HelloGitHub#4237 ·
-
enhancement localization
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
quarto-dev/quarto-cli#15268 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
oarepo/oarepo-ui#512 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days