share / share/sharedb-mongo

$aggregate query cannot be used with $comment or $hint

Open
#90 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
152
Forks
68
Avg merge
1d 5h
Merged PRs (30d)
3

Description

A query like this:

{
  $aggregate: [
    {$match: {species: 'sheep'}},
    {$count: {$sum: 1}}
  ],
  $comment: 'I am counting sheep'
}

Results in an error message "Cursor methods can't run after collection method $aggregate" coming from:
https://github.com/share/sharedb-mongo/blob/f746c0f34b649c140d352166e688d5541cb30671/index.js#L1027-L1031

The 3.x Mongo driver returns a cursor from db.collection.aggregate() and therefore allows further chaining, but the 2.x driver does not, which is why that check exists. One potential fix that would work with both versions - special-case aggregations to pass a comment/hint in the options when calling .aggregate().

Contributor guide

No contributing guide indexed for this repository

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

Read index.js around lines 1027-1031 and trace how $aggregate queries are dispatched for MongoDB driver versions 2.x and 3.x. Verify how $comment and $hint are handled, then confirm that an aggregate query accepts those options without the cursor-method error under both driver behaviors.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.