Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using MongoDB Atlas Search #2636

Answered by GromNaN
imunisasi asked this question in Q&A
Discussion options

Hello , is this possible to search using this one :
https://www.mongodb.com/atlas/search

any example for this , or just using normal search ?

thanks

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

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],
 ]
}));
You must be logged in to vote
2 replies
Comment options

thanks a lot @GromNaN ,
in Atlas search there is a score in result
how to showing score in this result ?

Comment options

I don't know Atlas Search enough to answer. You can look at the $search documentation. For Laravel integration, you can add an attribute to your model to receive this the score value (don't save it).

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

AltStyle によって変換されたページ (->オリジナル) /