Basically, what I want is to search data by username (which is displayName Field)

Below is how my profiles collection is like.

enter image description here

async localUsers(){       
        await authorizePromise;
        const {radius} = UserStateService.getState();
        console.info('Getting local users with radius', radius);

        const opts = {
            ...proximityHashOpts,
            ...proximityRangeOpts[radius],
            ...store.position,
        };

        const hashes = proximityhash.createGeohashes(opts);

        const profiles = firebase.firestore().collection('profiles');

        let queries = hashes.map(hash => rangeQueryParams(hash))
            .map(range => profiles.where('hash', '>=', range.start).where('hash', '<', range.end).get());

        const ME = UserProfileStore.getProfile();

        const results = await Promise.all(queries);

        return []
            .concat(...results.map(_ => _.docs))
            .filter(_ => !UserProfileStore.isForbiddenRelationship(_.id || _.id === ME.id))
            .filter(_ => _.data().visible !== false)
            .sort((a, b) =>{
                return b.data()['lastSeen'] - a.data()['lastSeen'];
            });
    }

So above localUsers function here fetches data from 'profiles' collection and where this line where('hash', '>=', range.start).where('hash', '<', range.end). fetches data on the basis of hash Field.

But I want to do is to fetch data on the basis of displayName Field and change the queries variable like below.

 let queries = hashes.map(hash => rangeQueryParams(hash))
            .map(range => profiles
            .where('hash', '>=', range.start).where('hash', '<', range.end)
            .orderBy('hash')
            .orderBy('displayName')
            .startAt(username)        // username is the value user enters
            .endAt(username + '\uf8ff')
            .get()); 

And the above queries doesn't return anything.

I know the code seems complicated, it is for me too because I'm redesigning this application which is already on Google Play.

0 Answers