Skip to content

Using MongoDB Atlas Search #2636

Answered by GromNaN
imunisasi asked this question in Q&A
Oct 9, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Yes, it is possible using a raw aggregation. There is an example in the mongodb library: https://github.com/mongodb/mongo-php-library/blob/0017da3d475a7795cb0577f4991b385992e51573/examples/atlas-search.php#L98

To use with laravel:

use MongoDB\Laravel\Collection;

YourModel::raw(function (Collection $collection) {
    return $collection->aggregate([
        [
            '$search' => [
                'index' => 'default',
                'text' => [
                    'query' => <text>,
                    'path' => [<field>],
                ],
            ],
        ],
        ['$limit' => 10],
    ]
}));

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@imunisasi
Comment options

@GromNaN
Comment options

Answer selected by imunisasi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants