I am creating a search bar where you can search for other users using firebase. I am currently struggling with querying through all my documents in my usernames collection, and checking if the users text input starts with what the user inputted. So for example, if 'Jessi' is searched, I would want to retrieve all users that start with those letters, such as 'Jessica' and 'Jessie'. I have tried many different solutions but am unable to complete the process.
This is what I have at the moment:
const searchUser = () => {
const usersRef =
firestore()
.collection('usernames')
.where('userName', '>=', username)
.where('userName', '<=', username= + '~').get()
console.log('usersRef', usersRef)
}
This however, returns an error: 'username' is read only.
These are my security rules:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read;
allow write: if request.auth != null;
}
}
}
Any help would be greatly appreciated. I am really struggling here.