To query the builder section model content based on locale using MongoDB operatores, you will need to use specific MongoDB operators within your query. The key parameters to focus on are query.query.$elemMatch.$and[0].property
and query.query.$elemMatch.$and[0].value
. These parameters together form a query that filters content where the locale
property equals fr
.
REST API Example
Here is an example of how you can use the REST API to query product pages where the locale is fr
:
https://cdn.builder.io/api/v3/content/your-model-name?apiKey=YOUR-API-KEY&query.query.$elemMatch.$and[0].property=locale&query.query.$elemMatch.$and[0].operator=is&query.query.$elemMatch.$and[0].value=fr&limit=100&fields=query,id,name
Query Breakdown
In this query, we use the following structure:
{
"query": {
"$elemMatch": {
"$and": [
{
"property": "locale",
"value": "fr"
}
]
}
}
}
Next JS example
const builderModelName = "product-page";
const content = await builder
// Get the page content from Builder with the specified options
.get(builderModelName, {
enrich: true,
options: {
cachebust: true,
noTargeting: true,
},
query: {
"query": {
$elemMatch: {
$and: [
{
"property": "locale",
"value": "fr"
}
]
}
}
},
})
// Convert the result to a promise
.toPromise();
This query ensures that we filter the content pages to include only those where the locale
property is set to fr
.
Note: You should be able to query the same using just userAttributes.locale=whatever
For more detailed information on querying Builder.io’s Content API, you can refer to the Content API Documentation.
Thanks,