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

NodeJS Aggregation method does not return same thing as aggregation using CLS

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.5.9
    • Component/s: None
    • Labels:

      I have my aggregation method like this:

      db.users.aggregate({ "$match": { "sessionData.idToken": "mySessionIdToken" } }, {
        "$project": {
          "issuesStatuses": {
            "$filter": {
              "input": "$issuesStatuses",
              "as": "issueStatus",
              "cond": { "$eq": ["$$issueStatus.issueId", "Daredevil_Vol_1_1"] }
            }
          },
          "favourites": { "$filter": { "input": "$favourites", "as": "favourite", "cond": { "$eq": ["$$favourite", "Daredevil_Vol_1_1"] } } },
          "ignored": { "$filter": { "input": "$ignored", "as": "ignore", "cond": { "$eq": ["$$ignore", "Daredevil_Vol_1_1"] } } }
        }
      })
      

      And this is the thing I'm pasting in command and I get only data where "issue_id" is equal to "Daredevil_Vol_1_1".

       

      Because in issuesStatuses are hundreds or thousands of other records, and I'm only interested in only one specific.

       

      But when I'm using NodeJS lib:

        async aggregateAsync(collection, pipeline, options) {
          return this
            .db()
            .collection(collection)
            .aggregate(pipeline, options);
        }
      
      and pipeline and options are:
      return this.#dbConnection.aggregateAsync(
            "users",
            {
              $match: { "sessionData.idToken": idToken }
            },
            {
              $project: {
                issuesStatuses: {
                  $filter: {
                    input: "$issuesStatuses",
                    as: "issueStatus",
                    cond: { $eq: ["$$issueStatus.issueId", issueId] }
                  }
                },
                favourites: {
                  $filter: {
                    input: "$favourites",
                    as: "favourite",
                    cond: { $eq: ["$$favourite", issueId] }
                  }
                },
                ignored: {
                  $filter: {
                    input: "$ignored",
                    as: "ignore",
                    cond: { $eq: ["$$ignore", issueId] }
                  }
                }
              }
            }
          );
      

       It returns all from all for issuesStatuses, favourites and ignored. That mean thousands of those records.

      I do copied from debug values and paste it into my command line, and everything worked as expected.

      That's why I think it's a problem with library - unless I don't find an issue that I'm using it wrongly - as well very big probability  

       

      What would you need more to help me here?

      db example:

       
      {
              "_id" : "1",
              "sessionData" : {
                      "idToken" : "mySessionIdToken",
                      "userId" : "1",
                      "userName" : "Szymon"
              },
              "issuesStatuses" : [
                      {
                              "issueId" : "Daredevil_Vol_1_1",
                              "characters" : [
                                      "Carl_Creel_(Earth-616)",
                                      "Matthew_Murdock_(Earth-616)"
                              ],
                              "status" : "character"
                      },
                      {
                              "issueId" : "Journey_into_Mystery_Vol_1_114",
                              "characters" : [ ],
                              "status" : "read"
                      }
              ],
              "favourites" : [
                      "Amazing_Spider-Man_Vol_5_6",
                      "Amazing_Spider-Man_Vol_5_14",
                      "Daredevil_Vol_1_1"
              ],
              "ignored" : [ ]
      }
      

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            elune90@gmail.com Szymon Walkowski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: