Zubatman
Zubatman

Reputation: 1305

Using Atlas Search with Mongoid on Rails

I am trying to get full text search with Atlas to work in my Rails app. I have set up the index following this tutorial in their docs. When I test the query in a vacuum it seems to work as expected, I'm able to query my database and get the results I would expect, but it seems like the documentation around how to do this in Mongoid is lacking. I have found this documentation for running text search in Mongoid, but it explicitly calls out that it isn't Atlas Search.

Has anybody successfully implemented an Atlas Search index/query using Mongoid (or otherwise in a Rails app) and, if so, could you please point me towards the relevant docs.

Upvotes: 1

Views: 228

Answers (1)

Zubatman
Zubatman

Reputation: 1305

Alright - after some experimentation with this I have found that the following code will work with the current version of mongoid:

TableName.collection.aggregate([{
    '$search' => {
        'index' => 'index_name',
        'text' => {
            'query' => 'some string to search',
            'path' => {
                'wildcard' => '*'
            }
        }
    }
}])

Upvotes: 0

Related Questions