Custom Query with $and (aggregation)

Hello !! I’m trying to make this simple custom query:

find(ctx) {
return strapi.query("geoinfo").find({
$and: [{ latitude: { $gt: ctx.lat } }, { longitude: { $gt: ctx.lng } }],
});
}

But im getting this 400 error:

“message”: “Your filters contain a field ‘$and’ that doesn’t appear on your model definition nor it’s relations”

Which is the right way to do this? Thank you !

It looks like you are trying to use mongoose methods for filtering, for Strapi’s version of complex filtering see: https://strapi.io/documentation/v3.x/content-api/parameters.html#complex-queries

Else you can use the custom queries to do it via mongoose: https://strapi.io/documentation/v3.x/concepts/queries.html#custom-queries

Hello Mehaffy, thanks for answering, yes I have read the documentation. Im trying to do a custom query via mongoose. That is my example, but im getting that error. What is the correct way to do it?

You need to use strapi.query().model.find() for mongoose (you are missing the .model)

1 Like

Hello. @DMehaffy. there are no 2 URLs currently. where can I see these URLs now?
I need to query using aggregate.

For docs?