feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 744 forks source link

Error using $search in mongo pipeline #3261

Closed ericuldall closed 7 months ago

ericuldall commented 11 months ago

Steps to reproduce

I'm running the following query

const agg = await this.app.service(query.collection).find({
      pipeline: [{
        $search: {
          "index": index.key,
          "autocomplete": {
            "path": index.path,
            "query": query.text,
            "tokenOrder": "any",
            "fuzzy": {
              "maxEdits": 2,
              "prefixLength": 1,
              "maxExpansions": 256
            }
          }
        }
      }],
      paginate: false
    });

The Error

error: MongoServerError: $_internalSearchMongotRemote is only valid as the first stage in a pipeline

I'd like to be able to run the pipeline and subsequently have all the hooks run. Is this possible?

ericuldall commented 7 months ago

Still not sure why this is the case but I found a work around accessing the mongo client directly:

const client = await this.app.get('mongodbClient');
const agg = await client.collection(query.collection).aggregate([{ $search }]);