apache / apache/grails-core

$text and $search pipeline does not work on multitenant domain

Open
#14,383 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-mongodb
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Hello,

Mongodb documentation says:

**$text:**
`The $match stage that includes a $text must be the first stage in the pipeline.`

**$search (Mongodb Atlas search):**
`$search must be the first stage of any pipeline it appears in. `

When querying a multitenant domain, we get an error because in the [preparePipeline](https://github.com/grails/gorm-mongodb/blob/9bc5f32fc76073415af5852f8ecdf500e5d58221/grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/gorm/mongo/api/MongoStaticApi.groovy#L287) a filter on current tenantId is always inserted as the first stage in the pipeline.

Thanks,

Contributor guide

Open the contributing guide

Research direction

Start in grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/gorm/mongo/api/MongoStaticApi.groovy at preparePipeline. Reproduce a multitenant query using $text and $search, then compare the generated pipeline with MongoDB's requirement that those stages come first. Done means both query forms work without the current-tenant filter causing an invalid pipeline.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, mongodb
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.