I’m new to NoSQL databases and wonder wonder if theres some core concepts i’m missing as i suppose this is a basic need many are facing using them for the first time.
I am building an App that lets Users create customized playlists via the Spotify API. The settings for a playlist get saved on a MongoDB database in the respective Users Document as a Subdocument.
Following the recommandations for NoSQL data structures i chose to have one collection for now that stores everything relevant for one User (avoiding relations). This is how a User Document could look like:
user: {
_id: ...,
name: 'spotify_user',
spotify_id: 'spotify_user324',
playlists: [
{
playlist_id: 'plalist_id_1',
seeds: [Array],
rules: [Array],
_id: 'mongo_id_1'
},
{
playlist_id: 'plalist_id_1',
seeds: [Array],
rules: [Array],
_id: 'mongo_id_2'
}
],
}
Hickup:
On the main page i get a Users Document using the spotify_id stored in the token, to display the playlists a User created. Clicking in one redirects to a new page displaying the settings for a playlist giving the user the ability to change them.
Now i’m finding myself in the need to fetch the whole Document on the playlist page again to retrieve the correct settings. This seems redundant to me but also kind of most straight forward way to prevent collisions on edge cases. (e.g. user uses app on different browsers)
I’ve thought about ways to prevent redundant calls but can’t find any recommandations or best practices, although i was sure this was a standard problem because of the nature of NoSQL data structures.
- One way i thought of: Saving the data to localStorage and check if localStorage is definded before fetching again. (But this introduces the possibility of outdated data, when User opens the Playlist directly through a link in the playlistdescription in spotify, so to be sure i would also need to fetch the whole document again)
Is there something i’m missing?
moerae is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.