Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ericyhwang opened this issue Sep 16, 2020 · 0 comments
Open

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

ericyhwang opened this issue Sep 16, 2020 · 0 comments

Comments

@ericyhwang
Copy link
Contributor

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:

sharedb-mongo/index.js

Lines 1027 to 1031 in f746c0f

if (collectionOperationKey && foundCursorMethod) {
return ShareDbMongo.cursorAndCollectionMethodError(
collectionOperationKey
);
}

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().

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

No branches or pull requests

1 participant