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

Aggregate and filter with full text indexes #54

Open
bprinsloo opened this issue May 21, 2020 · 1 comment
Open

Aggregate and filter with full text indexes #54

bprinsloo opened this issue May 21, 2020 · 1 comment

Comments

@bprinsloo
Copy link

Maybe I am missing something, but I can't get the $lookup to work with full text searches. I have a profile object which is a one to one to the users object (Decided to extend it). To pull in the in the users it seems aggregate was the most obvious choice. I want to use the following find in the aggregate:

profile.find(
        { $text: {
            $search: query
          }
        },
        {
          fields: {
            score: {
              $meta: 'textScore'
            }
          },
          sort: {
            score: {
              $meta: 'textScore'
            }
          }
        }
      );

An aggregate without the text query work. But using the above in an aggregate using the property observeSelector get "unknown operator: $text". I think my search translation into the aggregate might be faulty.

@bprinsloo
Copy link
Author

bprinsloo commented May 22, 2020

I solved it in the end. My publish function use it as follows:

ReactiveAggregate(this, profile, [
          {$match: {
            $text: {
              $search: query
            }
          }            
        }
        ,
          {            
            $lookup: {
                from: "users",
                localField: "__userid",
                foreignField: "_id",
                as: "users"
              }
            }],
            {
              fields: {
                score: {
                  $meta: 'textScore'
                }
              },
              sort: {
                score: {
                  $meta: 'textScore'
                }
              } 
            }
            )

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