Skip to content

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

Description

@ericyhwang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions