JD
JD
TTCTheo's Typesafe Cult
Created by JD on 11/3/2023 in #questions
Frontend dev trying to fullstack - confused by options
I am almost exclusivley a frontend dev, trying to branch out and build a full stack app with NEXTjs, drizzle and planetscale. I keep finding myself struggling with option paralysis trying to decide if I have complex SQL to minimise work in the app or lots of simple SQL queries that need complex functions to join them all together. I know the answer i likely *"it depends" * but can anyone recommend any good articles or youtube videos on best practice and practical tips when planning and building the interactions between database and app. My current specific scenario is a family charity letting parents know about support groups. It has a table of groups, with the following joins: - a one to many join to openingTimes that has the weekday, startTime, endTime - a one to many join to contactDetails that has type and value (i.e. facebook, phone etc) - a many to many join (via a junction table) to attendeeTypes that has name, description (i.e. babies, toddlers, preschool, parents etc) How would you handle displaying all the groups including all the opening hours, contact details and the attendee types? - simple SQL query for each table, and manually join in the app? - complex drizzle query to get all the data into the specific format ( is it even possible - best I end up with several empty parent objects that still need manipulation) - something else?
2 replies
TTCTheo's Typesafe Cult
Created by JD on 12/11/2022 in #questions
How to filter the SpaceX API (mongoDB find() based) by a nested array?! Tech Test
I'm stuck on a tech test where I need to call the spaceX API and filter all launches in the response based on an array of payloads including a specific nationality string. The the response normally has only a list of payload ids, but the full payload data is populated via options object. Link to API docs: https://github.com/r-spacex/SpaceX-API/blob/master/docs/queries.md I've been going through all the mongoDB docs trying to get my head around the syntax, but keep either getting all data unfiltered, or none, or an error. Been trying for days, and the I know from the recruiter that others have failed because they failed to add in this specific filter in past tech tests. I'm currently getting this error:
Cast to ObjectId failed for value "{ nationalities: 'United States' }" (type Object) at path "payloads" for model "Launch"
Cast to ObjectId failed for value "{ nationalities: 'United States' }" (type Object) at path "payloads" for model "Launch"
This is the body I am sending:
{
"query": {
"payloads": {"nationalities": "United States"}
},
"options": {
"pagination": true,
"select": {
"date_utc": 1,
"links": 1,
"payloads": 1,
"flight_number": 1,
"name": 1,
"success": 1,
"upcoming": 1
},
"populate": [
{
"path": "payloads",
"select": {
"nationalities": 1
},
"retainNullValues": true
}
],
"sort": {
"date_utc": "desc"
}
}
}
{
"query": {
"payloads": {"nationalities": "United States"}
},
"options": {
"pagination": true,
"select": {
"date_utc": 1,
"links": 1,
"payloads": 1,
"flight_number": 1,
"name": 1,
"success": 1,
"upcoming": 1
},
"populate": [
{
"path": "payloads",
"select": {
"nationalities": 1
},
"retainNullValues": true
}
],
"sort": {
"date_utc": "desc"
}
}
}
Would really appreciate any suggestions.
10 replies