Hi!
Weâre working to move a poorly designed Dating type app from a WordPress/MySQL backend to Parse with a MongoDB NoSQL database. The previous app wonât scale and just wasnât built well.
Before we get too far into the development, looking for advice or best practices for setting up the database schema for ease, indexing, queries, etc.
Most everything in the app is related to a user (their login (email, password), their username for the dating app, birthdate, preferences, what they are looking for (traits, likes, dislikes), their profile pics, and even their geo location so other users can filter and see users around them.
A suggested schema is below, where literally all of this is in the one user collection. This is neat and tidy, but is there any downside to this? Would there be any reason that authentication details and then user profile details should be separate and linked by their uniqueIDâs? Same with location, where we store their geo coordinates, which will change often as they move around - is it ok to also have that in the user document or should another collection be creates solely for tracking geopoints? There are also one to many/relational type data items to store as well, such as who this user has blocked, who they have marked as liked, etc. Assuming these types of things can be stored in arrays, but again, is it ok to have all of this under the user collection, or should things like âlikedâ and âblockedâ be separate collections? Itâs sometimes hard to get your head around the differences between SQL and NoSQL where these types of data would need to be separate relational tables, but in NoSQL they could theoretically all exist in one collection.
Thanks for any advice on this, weâve seen it done a variety of ways and would love insight on the pros and cons.
Finally, if anyone sees any red flags with using MongoDB for this, i know NoSQL can be tricky with queries, weâll need to be able to filter users by location, presence (on/offline), and traits/characteristics, including ranges (like if a user wants to see everyone around them that is online, between ages of 18 and 45), etc.
Thank you!
A rough idea of the schema with everything under the user collection:
{
â_idâ: ObjectId(âunique user IDâ),
âusernameâ: âuser123â,
âemailâ: â[email protected]â,
âpasswordâ: âhashed_passwordâ,
âbirthdateâ: ISODate(â1990-01-01T00:00:00Zâ),
âgenderâ: âmaleâ,
âlocationâ: {
âtypeâ: âPointâ,
âcoordinatesâ: [longitude, latitude]
},
âphotosâ: [âurl1â, âurl2â],
âbioâ: âA little bit about meâŚâ,
âinterestsâ: [âhikingâ, âcookingâ, âmoviesâ],
âattributesâ: {
âheightâ: 175, // in cm
âeducationâ: âPh.D.â,
âoccupationâ: âSoftware Engineerâ,
// Other attributesâŚ
},
âlikesâ: [âuser456â, âuser789â],
âdislikesâ: [âuser234â],
âmatchesâ: [âuser987â],
âblockedUsersâ: [âuser567â],
âcreatedAtâ: ISODate(â2023-10-18T12:00:00Zâ),
âupdatedAtâ: ISODate(â2023-10-18T15:30:00Zâ)
}