Shivam Sahil
Shivam Sahil

Reputation: 4925

Firebase: Maintain a Username Directory

I am creating a Social app and want to track if a username already exists or not. The username list is supposed to grow in future and the way I was doing it now was a key value pair of <string,bolean> like this:

name1: true,
name2: true

all the above data was to be stored in a single document and whenever I want to see if a user exists I would call this document and check accordingly. But here's the problem, firebase max document size is 1MBs and as the users grow this can be problematic, so wanted to know from firebase experts that what's the best way to solve this use case in firestore or realtime database but since I need to query exists maybe realtime db won't suit that well.

Note that I don't want any of firestore querying capabilities but only to check if an entry exists in the record or not and if not just add it.

Upvotes: 0

Views: 26

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599766

The Realtime Database doesn't have a 1MB limit (since it has no concept of a document, and everything is just a tree of JSON), so I'd typically use that for the index of user names.

Checking whether a name exists is pretty simple there too, and in JavaScript would look something like:

const usernames = firebase.database().ref('usernames');
usernames.child('name1').once((snapshot) => {
  if (snapshot.exists()) {
    ...
  }
});

Upvotes: 1

Related Questions