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

[TypeScript] $search operator not correctly typed (highlight path option) #11372

Closed
lmX2015 opened this issue Feb 9, 2022 · 1 comment
Closed
Labels
typescript Types or Types-test related issue / Pull Request

Comments

@lmX2015
Copy link
Contributor

lmX2015 commented Feb 9, 2022

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

Bug

What is the current behavior?

$search operator (aggregation) is not correctly typed (for the highlight option). For example

import {Model, model, Schema} from "mongoose";

interface IUser {
    name: string;
    firstName: string;
    search(query: string): any;
}

// 2. Create a Schema corresponding to the document interface.
const schema = new Schema<IUser>({
    firstName: { type: String, required: true },
    name: { type: String, required: true },

});

schema.static("search", function(this: Model<IUser>, query: string) {
    return this.aggregate([
        {
            $search: {
                highlight: {
                       path : ["name", "firstname"], // "name" works fine
                },
                index: "searchLucene",
                text: {
                    path: ["name", "firstname"],
                    query,
                },
            },
        },
        {
            $project: {
                firstName: 1,
                highlights: { $meta: "searchHighlights" },
                name: 1,
                score: { $meta: "searchScore" },
        }},

    ]);
});
// 3. Create a Model.
const UserModel = model<IUser>("User", schema);

throws a compilation error (path should be a string not string[]).

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

What is the expected behavior?

From MongoDB documentation, "highlight.path" can be a string array.
So highlight.path should be at least string | string []

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

  • mongoose: 6.2.1
  • typescript: 3.3.3
  • node : 16.3.0
@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Feb 10, 2022
@vkarpov15 vkarpov15 added this to the 6.2.4 milestone Feb 12, 2022
@vkarpov15
Copy link
Collaborator

Fixed in v6.2.2 with #11373

@vkarpov15 vkarpov15 removed this from the 6.2.4 milestone Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants