Reputation: 87
We are using MongoDB Atlas Search Indexes to query and filter the documents list. consider below document.
{_id:5sfgdfgf2c46e0fb00019bdecc, user_id:4996, bom_number:"112", name:"test"}
Created default Index:
{ "mappings": { "dynamic": false, "fields": { "user_id": { "type": "string" } } } }
Query:
{ text: { query: ["4996","3888"], path: 'user_id' } }
It is not returning any documents. Can anyone please guide. I know we actually stored user_id as numeric form and I tried indexing and querying the field as String. Please help me out and suggest correct way of querying mongo atlas numeric field with multiple values.
Upvotes: 2
Views: 867
Reputation: 719
$search
is what you need to use to query using the index that you have created and you also need to mention the name of the index in the query.
The below draft might help you:
$search:{
{
index: "index_name_created_from_atlas_search",
text: {
query: "<actual data you need to search>",
path: "<field_name>"
}
}
}
And based on your example, if you want to have multiple conditions with the search, you can refer to official documentation here of all sorts of multiple conditions you can integrate with the $search
aggregation using the compound
operator.
Upvotes: 1