Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3567

$out method on AggregationCursor is not right typed or no doc related is available

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.2
    • Affects Version/s: None
    • Component/s: None
    • Not Needed

      What problem are you facing?

      Cannot use a code like this:

      ```typescript
      db
      .collection(snapshot)
      .aggregate([])
      .out("mycol")
      .toArray()
      .then(() => {});
      ```

      Note steps for the pipeline are not included because they are not relevant for the issue.

      What driver and relevant dependency versions are you using?

      ```
      node: v14.17.5 LTS
      npm: 7.21.0
      node-mongodb: 4.1.0
      ```

      Steps to reproduce?

      ```
      cd /tmp/
      mkdir test
      cd test
      npm init -y
      npm i mongodb
      mkdir src/
      echo 'import

      { Db } from "mongodb"; let db: Db; db.collection("coll").aggregate([]).out("mycollection").toArray().then(() => {});' > src/index.ts
      npx tsc src/index.ts
      ```

      This is the output:
      ```
      src/index.ts:1:83 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.

      1 import { Db }

      from "mongodb"; let db: Db; db.collection("coll").aggregate([]).out("mycollection").toArray().then(() => {});
      ```

      This is the related line of code: https://github.com/mongodb/node-mongodb-native/blob/b67af3cd/src/cursor/aggregation_cursor.ts#L132

      `out` should be either an string or an object:

      https://docs.mongodb.com/manual/reference/operator/aggregation/out/

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            loksly@gmail.com M Loksly
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: