Closed fimbres closed 6 months ago
@fimbres
I think it's because you defined Lat and Long as a String in your schema.
You need to use Float or Int for the filter to be able to work.
GraphQL model
type Affiliate @model @searchable {
id: ID!
name: String!
lat: Float!
lng: Float!
}
Hey @ChristopherGabba lol you were right. I thought it was already a Float. But now after migrating it seems that any Float comparison is not returning data at all. I did the migration and in my db all Affiliate's records have lat & lng of type number. But even if I do something like this:
lat: {
eq: 31.8754079,
},
it's not returning any data. using eq with the name field (String) works tho. any idea on this one?
Disclaimer, I'm some random struggling with DynamoDB as well.
Without seeing your data, and knowing what's in there, the filter
line just filters the first set of results after they have been fetched. I've struggled a lot here, but I think you may need to set up secondaryIndex queries for your data with sortKeys, instead of using the filter expression.
For example, lets say I just use a basic list query like you have used to find all people with the first name John.
If I have 500 users registered, and I set my query limit to 100, it's going to read through the first 100 people in the database and completely ignore the next 400 unless I provide a nextToken. That's called a scan
query in dynamoDB vs. a query
operation, and its basically worthless for most applications. I honestly don't know why they even structure that option. Instead you assign the firstName as a secondaryIndex and it actually queries all your data for people with a first name as John
.
That being said, using your filter expressions like you did above is going to get the first say 100 affiliates in your database and then filter them by your data, because you are using the scan
method. Also using the eq
flag is only going to get fields with that exact number. As an experiment to test your query, make the limit on your query above to like 1000000000 and see if you get results, but don't use this in production because it will be expensive. You need to set up secondaryIndexes.
I'm going to close this issue as the original issue has been solved thanks to @ChristopherGabba, but I would recommend opening a new one regarding the issue of no data being returned to track it separately as a potential bug and with details for the team to reproduce
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
api
Backend
Amplify CLI
Environment information
Describe the bug
I'm trying to get all the records in my db filtering by lat and lng, I have a range for each field (lat, lng)
for lat it's all good because I don't have negative numbers. but for lng it's not passing.
In the following example you can see this is correct:
-172.9272442976304 <= -116.604305 && -116.604305 <= -60.28136570236959
. But for the amplify filters it's not correct.This is my query statement:
it does not return any data when it should. Also if the minLng is bigger than the second one I get this error:
for example: -90 and -120 triggers the error, but -120, and -90 doesn't. It's kinda like if the values are parsed to positive to make the comparison or something like that. Because -90 is bigger than -120.
So I'm just wondering if there's any solution for this, in order to filter using negative values as lat, lng.
Expected behavior
Filter the records in my db in order to get the nearest to the user.
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
Iphone 15 pro Simulator
Mobile Operating System
IOS 17.4
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response