jeudi 25 janvier 2018

Nodejs & Mongo pagination random order

I am running an iOS app where I display a list of users that are currently online.
I have an API endpoint where I return 10 (or N) users randomly, so that you can keep scrolling and always see new users. Therefore I want to make sure I dont return a user that I already returned before.
I cannot use a cursor or a normal pagination as the users have to be returned randomly.

I tried 2 things, but I am sure there is a better way:

  • At first what I did was sending in the parameters of the request the IDs of the user that were already seen. ex: But if the user keeps scrolling and has gone through 200 profiles then the list is long and it doesnt look clean.
  • Then, in the database, I tried adding a field to each users "online_profiles_already_sent" where i would store an array of the IDs that were already sent to the user (I am using MongoDB)

I can't figure out how to do it in a better/cleaner way

Thank you :)




Aucun commentaire:

Enregistrer un commentaire