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

$function support (MongoDB 4.4) #9897

Closed
eliw00d opened this issue Feb 4, 2021 · 0 comments
Closed

$function support (MongoDB 4.4) #9897

eliw00d opened this issue Feb 4, 2021 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@eliw00d
Copy link

eliw00d commented Feb 4, 2021

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
I get MongoError: Invalid $addFields :: caused by :: The body function must be specified. unless I add .option({ serializeFunctions: true }), similar to #9364.

Also, I have the object-shorthand eslint rule turned on and it turns:

const documents = await Model.aggregate([
  body: function() {
    // logic
  },

into:

const documents = await Model.aggregate([
  body() {
    // logic
  },

which gives a MongoError: SyntaxError: unexpected token: '{' error.

If the current behavior is a bug, please provide the steps to reproduce.

const documents = await Model.aggregate([
    {
      $addFields: {
        newField: {
          $function: {
            body: function(oldField: any) {
              // logic using oldField
            },
            args: ['$oldField'],
            lang: 'js',
          },
        },
      },
    },
  ])

root/tsconfig.json

{
  "compilerOptions": {
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "skipLibCheck": true
  }
}

root/subfolder/tsconfig.json

{
  "compilerOptions": {
    "lib": ["es2020"],
    "sourceMap": true,
    "strict": true,
    "target": "es2020"
  },
  "extends": "../tsconfig.json"
}

What is the expected behavior?
It should serialize by default, similar to $accumulator.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

Mongo 4.4.3, Mongoose 5.10.11, Node 14.15.0

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Feb 8, 2021
@vkarpov15 vkarpov15 added this to the 5.11.16 milestone Feb 8, 2021
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed typescript Types or Types-test related issue / Pull Request labels Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants