Query by namespace and filter by metadata

Hello, good morning. I have created a namespace to store my products, and each product carries metadata with some special parameters for each product. When I query by namespace, it generates a correct result

But when I include a metadata filter, the result is empty. I have tried including MongoDB query language as it appears in the documentation, but the result is the same.

What can I do to obtain a result within the namespace and also filter by metadata? Is it possible?

Hi @luisfmartinez1303,

Thanks for your question and I’m sorry you’re encountering this issue.

Your query looks correct to me and you’re passing the same namespace in both places, so that would rule out a namespace mismatch.

Here’s a couple of other things to double-check:

Type Matching: Ensure that the type of company_id in the metadata and the query matches. If company_id is stored as a number in the metadata, then the query should filter by number, not a string. Try:

filter={"company_id": 1000001}

Validation with Another Metadata Key: As a test, try querying with another metadata key-value that you are sure exists in the database. This will help identify if the issue is specific to company_id or if it’s more generalized.

For example, if there’s a known product title:

filter={"product_title": "Helado de Yogurt Probiótico con Maracuyá y Aguaymanto 500ml"}

I hope that helps shake something loose - and if not let me know!