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

Migration from mongoose 7 to 8.8.0 breaks repository with (responseType ?? responses_1.MongoDBResponse).make is not a function error #15030

Open
1 task done
cjones27 opened this issue Nov 11, 2024 · 3 comments
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary interop issue issue with interop between Mongoose and another npm module that is not a Mongoose prod dependency

Comments

@cjones27
Copy link

Prerequisites

  • I have written a descriptive issue title

Mongoose version

8.8.0

Node.js version

20

MongoDB version

7.0.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

No response

Issue

Hi! I have being upgrading mongoose version from 5 to 7 and finally 8. I encountered a problem on one of our microservices going from 7.6.3 running node 20 on aws lambda to mongoose 8.8.0 that I haven't been able to understand. Our schema is the following

import mongoose, { Schema } from 'mongoose';

const AgreementSchema = new Schema<Agreement>(
  {
    legalEntity: {
      type: {
        documentNumber: { type: String, required: true },
      },
      required: true,
    },
    companyInformation: {
      type: {
        constitutionType: { type: String, enum: Object.values(ConstitutionType), required: true },
        documentNumber: { type: String, required: true },
        companyName: { type: String, required: true },
        address: {
          type: {
            street: { type: String, required: true },
            streetNumber: { type: String, required: true },
            municipality: { type: String, required: true },
            city: { type: String, required: true },
            state: { type: String, required: true },
            countryName: { type: String, required: true },
            locationDetails: {
              locationType: { type: String, enum: Object.values(AddressLocation) },
              locationDescription: { type: String },
            },
          },
          required: true,
        },
      },
    },
    signatories: {
      type: [
        {
          type: {
            documentNumber: { type: String, required: true },
            name: { type: String, required: true },
            email: { type: String, required: true },
            role: { type: String, required: true, enum: Object.values(SignatoryRole) },
            participationPercentage: { type: Number },
            signatureStatus: { type: String, enum: Object.values(SignatureStatus) },
            maritalStatus: { type: String, enum: Object.values(MaritalStatus) },
            signatureDate: { type: Date },
            spouse: {
              type: {
                documentNumber: {
                  type: String,
                  required: true,
                },
                name: { type: String, required: true },
                email: { type: String, required: true },
                signatureStatus: { type: String, enum: Object.values(SignatureStatus) },
                signatureDate: { type: Date },
              },
            },
          },
        },
      ],
    },
    signatureDate: { type: Date },
    signatureGroupId: { type: String },
    signatureStatus: { type: String, enum: Object.values(SignatureStatus) },
    depositAccount: {
      type: {
        documentNumber: { type: String, required: true },
        accountNumber: { type: String, required: true },
        bankName: { type: String, required: true },
        bankCode: { type: String, required: true },
        accountType: { type: String, required: true },
        email: { type: String, required: true },
      },
      required: false,
    },
  },
  {
    timestamps: true,
    toJSON: { virtuals: true },
  },
);

AgreementSchema.index({ 'legalEntity.documentNumber': 1 }, { unique: true });

export const AgreementModel = mongoose.model<Agreement>('Agreement', AgreementSchema);

And the repository that uses that model is the following (erroring on both repository methods):

export const AgreementRepository = (): AgreementRepositoryInterface => ({
  upsert: async ({ agreement }) => {
    await initDatabase();

    const upsertedAgreement = await AgreementModel.findOneAndUpdate(
      { 'legalEntity.documentNumber': agreement.legalEntity.documentNumber },
      {
        $set: agreement,
      },
      {
        upsert: true,
        new: true,
      },
    );

    return upsertedAgreement.toJSON<Agreement>();
  },
  getByDocumentNumber: async ({ documentNumber }) => {
    await initDatabase();

    const agreement = await AgreementModel.findOne({
      'legalEntity.documentNumber': documentNumber,
    });

    return agreement ? agreement.toJSON<Agreement>() : null;
  },
});

Yet, when upgrading to 8.8.0, the query fails with the following error:

(responseType ?? responses_1.MongoDBResponse).make is not a function","stack":"TypeError: (responseType ?? responses_1.MongoDBResponse).make is not a function\n    at Connection.sendWire (/opt/nodejs/node_modules/mongodb/lib/cmap/connection.js:243:80)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async Connection.sendCommand (/opt/nodejs/node_modules/mongodb/lib/cmap/connection.js:280:24)\n    at async Connection.command (/opt/nodejs/node_modules/mongodb/lib/cmap/connection.js:317:26)\n    at async Server.command (/opt/nodejs/node_modules/mongodb/lib/sdam/server.js:167:29)\n    at async FindOperation.execute (/opt/nodejs/node_modules/mongodb/lib/operations/find.js:34:16)\n    at async tryOperation (/opt/nodejs/node_modules/mongodb/lib/operations/execute_operation.js:199:20)\n    at async executeOperation (/opt/nodejs/node_modules/mongodb/lib/operations/execute_operation.js:69:16)\n    at async FindCursor._initialize (/opt/nodejs/node_modules/mongodb/lib/cursor/find_cursor.js:51:26)\n    at async FindCursor.cursorInit (/opt/nodejs/node_modules/mongodb/lib/cursor/abstract_cursor.js:495:27)"}}

Haven't been able to solve it, so any recomendations to understand what could be going on would be greatly appreciated!

Thank you very much!

@cjones27 cjones27 added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Nov 11, 2024
@coderhammer
Copy link

Are you using datadog? We were facing the same issue. Upgrading the datadog tracer from 3 to 5 did the trick for us

@CatsMiaow
Copy link
Contributor

Are you using splunk? We were facing the same issue. Upgrading the @splunk/otel from v2.7.1 to v2.14.0 did the trick for us

@vkarpov15
Copy link
Collaborator

This looks like an issue with the @opentelemetry/instrumentation-mongodb package, likely this commit: open-telemetry/opentelemetry-js-contrib@9dc55da. Run npm list @opentelemetry/instrumentation-mongodb and make sure you're using at least @opentelemetry/[email protected].

@vkarpov15 vkarpov15 added interop issue issue with interop between Mongoose and another npm module that is not a Mongoose prod dependency and removed help wanted labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary interop issue issue with interop between Mongoose and another npm module that is not a Mongoose prod dependency
Projects
None yet
Development

No branches or pull requests

4 participants