MongoDB Meteor 2.12

Hello, I’m in the process of updating the meteor version of my project that used to be 1.0.12 and after updating to the 2.12 I’m facing this error related to the aggregate of the mongodb. In the image there is the code, the error and the packages I have installed:

I’ve serched the issue and what they say is that this is a bug actually and it has been corrected in the 6.0.7 version of the mongodb.

This makes me think if there is any way to bypass this because Meteor 2.12 uses by default mongo 6.0.3 and the production databases that I have with atlas are currently in 6.0.5. So I’m really concerned about this and thinking if it will really be possible to update the meteor version in production.

Thanks in advance for any help.

I think you can remove the package meteorhacks:aggregate and use something like the following instead:

import { Promise } from 'meteor/promise'

Mongo.Collection.prototype.aggregate = function (pipelines, options = {}) {
  return Promise.await(this.rawCollection().aggregate(pipelines).toArray())
}

Thank you so much, this solution worked. I put your code at the start of my code and removed the .toArray of my result… Here is the full code if anyone ever have the same issue.

import { Meteor } from "meteor/meteor";
import { Promise } from 'meteor/promise'
import _ from "lodash";

Mongo.Collection.prototype.aggregate = function(pipelines, options = {}) {
  return Promise.await(this.rawCollection().aggregate(pipelines).toArray());
};

Meteor.methods({
  examAuditForDoctorsInvoiceReport(startDate, endDate) {
    const header = "[method] [examAuditForDoctorsInvoiceReport]";
    // console.log(header, 'starting', requestedTenantIds, startDate, endDate)
    if (!(startDate && endDate)) {
      // console.log(header, 'startDate or endDate not provided -> skipping')
      return [];
    }

    const userId = this.userId;
    if (!userId) {
      // console.log(header, 'user not logged it -> skipping')
      return [];
    }

    const isGlobalAdmin = hasPermission(userId, "global:admin");
    if (!isGlobalAdmin) return [];

    const user = Meteor.users.findOne(userId);
    if (!user) {
      console.error(header, `failed to load user record for id ${userId} -> skipping`);
      return [];
    }

    let query = {
      startDate: { $gte: startDate, $lte: endDate },
      status: { $in: ["Concluído", "Revisão"] },
    };

    let fields = {
      userId: 1,
      status: 1,
      _id: 1,
      startDate: 1,
      examId: 1,
      "exam.tenantId": 1,
      "exam.type": 1,
      "exam.status": 1,
      "exam.doctorId": 1,
      "exam.reviewerId": 1,
      "exam.patientName": 1,
      "exam.requesterName": 1,
      "exam.createdAt": 1,
      "exam.healthPlan": 1,
      "exam.doctorName": "$exam.doctor.profile.fullName",
      "exam.reviewerName": "$exam.reviewer.profile.fullName",
    };

    let pipeline = [
      { $match: query },
      {
        $lookup: {
          from: "Exam",
          localField: "examId",
          foreignField: "_id",
          as: "exam",
        },
      },
      { $unwind: "$exam" },
      // { $match: { "exam.tenantId": { $in: authorizedTenantIdList } } },
      {
        $lookup: {
          from: "users",
          localField: "exam.doctorId",
          foreignField: "_id",
          as: "doctor",
        },
      },
      { $unwind: "$doctor" },
      {
        $lookup: {
          from: "users",
          localField: "exam.doctorId",
          foreignField: "_id",
          as: "exam.doctor",
        },
      },
      { $unwind: "$exam.doctor" },
      {
        $lookup: {
          from: "users",
          localField: "exam.reviewerId",
          foreignField: "_id",
          as: "exam.reviewer",
        },
      },
      // { $unwind: "$exam.reviewer" },
      { $project: fields },
    ];
    //console.log(header, "pipeline", pipeline);
    let result = Exam_Audit.aggregate(pipeline, { cursor: {} }) || [];
    return result;
  },
});

I am glad it worked. One mention: lodash is a very large library and that’s a problem if you import it at least one time somewhere on the client.
You can add lodash functions in your NPM instead of the whole library.
e.g.: [

lodash.isequal

](lodash.isequal - npm)

[

lodash.uniq

](lodash.uniq - npm)