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

no $option in FilterOperators for $regex? #405

Open
xb1g opened this issue Nov 29, 2023 · 0 comments
Open

no $option in FilterOperators for $regex? #405

xb1g opened this issue Nov 29, 2023 · 0 comments

Comments

@xb1g
Copy link

xb1g commented Nov 29, 2023

The code works but type show as error at $options

Argument of type '{ $or: ({ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; })[]; } | {}' is not assignable to parameter of type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }> | undefined'.
  Type '{ $or: ({ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; })[]; }' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>'.
    Types of property '$or' are incompatible.
      Type '({ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; })[]' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>[]'.
        Type '{ username: { $regex: string; $options: string; }; } | { name: { $regex: string; $options: string; }; }' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>'.
          Type '{ username: { $regex: string; $options: string; }; }' is not assignable to type 'Filter<{ provider?: ("google" | "facebook" | "discord" | "email")[] | undefined; devId?: string | ObjectId | undefined; discordId?: string | undefined; avatar?: string | undefined; ... 20 more ...; apps: (string | ObjectId)[]; }>'.
            Types of property 'username' are incompatible.
              Type '{ $regex: string; $options: string; }' is not assignable to type 'string | FilterOperators<string> | undefined'.
                Object literal may only specify known properties, and '$options' does not exist in type 'FilterOperators<string>'.deno-ts(2345)

  const users = await Users.find(
    search
      ? {
          $or: [
            { username: { $regex: search, $options: "i" } }, // 'i' for case-insensitive
            { name: { $regex: search, $options: "i" } },
          ],
        }
      : {},
    {
      projection: { password: 0 },
    }
  ).toArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant