This is the first mongo-backed-application I am trying to make beyond tutorials, so I lack imagination when it comes to document schemas.
Context:
On a dating application, there is an algorithm that identifies matches between users. Currently trying to identify how these matches should be stored.
Current schema:
Create two Match documents per pair (one for each user), each will hold the response of its user, a reference to the other user, and the id of its paired document:
Match : {
objectid: [unique uuid],
user: [idx, uuid],
targetUser: [reference to User],
pair: [Match uuid],
approved: [bool / null]
}
UseCase:
Algorithm creates the match objects. A request is made to fetch all potential User
matches, we query the database for all the Match
objects for User
, where approved is null
. The database will populate the targetUser
field with the actual User
document [!!!], and return. Results are serialized and sent back.
...
User approves match, request sent to update Match[objectid].approved = True
. Backend checks value of second Match object referenced by pair
and then fires other actions depending on value.
Concerns:
First of all, to someone more experienced with NoSQL this might seem horrible, in which case please tell me. My main concern is about having the reference to targetUser
. A big selling point of NoSQL is reducing the number of 'joins', yet I can't find a way of avoiding it here. Also, the fact that I have two objects for one pair is a bit troubling. But how else would I say: give me all potential matches for User A
?