question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong type to $in expr

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title

Mongoose version

6.4.0

Node.js version

16.14.2

MongoDB version

cosmosDB 4 - not really relevant

Operating system

Windows

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

WSL 2 - Ubuntu 20.04

Issue

I have received this issue

Type 'string[]' is not assignable to type '[Expression, ArrayExpression<any>]'. Target requires 2 element(s) but source may have fewer.

for this snippet:

{
    $match: {
        'data.sourceCurrency': { $in: ['USD', 'GBP', 'EUR'] },
    },
}

I’m not sure what more data to provide, but unless I’ve mistaken it looks like the $in an array is an array of 2 items which [Expression, ArrayExpression<any>] instead of Expression[] | ArrayExpression<any>[]

P.S: ArrayExpression covers T[] which includes string[] which is my type

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
heilmelacommented, Jun 19, 2022

im facing similiar problems with some aggregate pipelines

const pipeline: PipelineStage[] = [
      {
        $unwind: {
          path: '$sectors',
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $match: {
          organization,
          approved: { $exists: true, $ne: null },
        },
      }
  ]

Where i get Type 'null' is not assignable to type 'Expression | [Expression, Expression]'. Removing the $ne leaves me with Type '{ $exists: true; }' is not assignable to type 'Expression'.

2reactions
Uzlopakcommented, Jun 18, 2022

This is some inconsistency between the docs of mongo and real mongodb syntax. I will provide a fix tomorrow. I am currently not having access to my Laptop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PLS-00382: expression is of wrong type - Burleson Consulting
Question: What causes the PLS-00382 error? ... Cause: An expression has the wrong datatype for the context in which it was found. Action:...
Read more >
expression is of wrong type for function - Stack Overflow
In the function declaration, you said. RETURN EMP.ENAME%TYPE. I assume the data type of column ENAME in table EMP is some sort of...
Read more >
PLS-00382: expression is of wrong type - Ask TOM
PLS-00382: expression is of wrong type I get PLS-00382: expression is of wrong type in the following scenario:vemail VARCHAR2(80) DEFAULT NULL;for i in...
Read more >
Common Error Messages · OCaml Tutorials
"This expression has type X but is here used with type Y" means that if the contents of the expression is isolated (2.5),...
Read more >
scm-error-messages.txt - Department of Computer Science
ERROR : Wrong type to apply: (see errobj) ERROR: unbound variable: foo ERROR: if: missing or extra expression (see errobj) The subsections below...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found