Skip to content

How to query only documents with an existing localization for a certain locale? #5469

Answered by DanRibbens
hdodov asked this question in Q&A
Discussion options

You must be logged in to vote

I am fairly certain that the query builder does let you pass the locale through and that you should be able to just do one query. Also I do not think that querying uses the fallback locale at all. We don't have extra logic that would add or for the fallback for the properties being queried.

It is my expectation that this should work:

const posts = (
	await payload.find({
		collection: "blog-posts",
		locale: req.locale,
		where: {
			'content.es': {
				exists: true,
			},
		},
	})
).docs;

To format that into a rest query using query params you're looking at /api/blog-posts?where[content.es][exists]=true&locale=es
That should return your posts where content is populated in the es locale …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hdodov
Comment options

Answer selected by hdodov
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