codediodeio / geofirex

:globe_with_meridians: :round_pushpin: Geolocation Queries with Firestore & RxJS
https://geo-test-c92e4.firebaseapp.com/
477 stars 106 forks source link

Is paging possible with this library? #32

Open georgeMorales opened 5 years ago

georgeMorales commented 5 years ago

Is paging possible with this library? I got it with redux thunk and firestore but I do not know how I can put limits. I know that it is not possible with this library to query where 'birthday', '> =', today because it is already ordered by the geopoints, that is not a problem, what I do not know is how to create this function with the geoquery. Thanks for this wonderful library!

`//--------------------------onSnapshot listener------------------------------------ export const getUsersAction = (lastUsers) => async (dispatch, getState) => {

const today = new Date(Date.now());
const usersRef = firestore.collection('users')

try {

        let startAfter = lastUsers && (await firestore.collection('users').doc(lastUsers.id).get());

        let query;

        lastEvent
            ? (query = usersRef.where('birthday', '>=', today).startAfter(startAfter).limit(5))
            : (query = usersRef.where('birthday', '>=', today).limit(5))

        query.onSnapshot(async (querySnapshot) => {

            if (querySnapshot.docs.length === 0) {
                console.log('querySnapshot.docs.length === 0');

                return querySnapshot;
            }

            let users = [];

            for (let i = 0; i < querySnapshot.docs.length; i++) {
                let user = {...querySnapshot.docs[i].data(), id: querySnapshot.docs[i].id}
                users.push(user)
            }

    console.log(users)                

            return querySnapshot;

        }, (err) => {
            console.log('error onSnapshor', err);
        })
    }
    catch (error) {
        console.log(error);

}

} // ------------------------or not onSnapshot listener--------------------------------- export const getUsersAction = (lastUsers) => async (dispatch, getState) => {

const today = new Date(Date.now());
const usersRef = firestore.collection('users')

try {

        let startAfter = lastUsers && (await firestore.collection('users').doc(lastUsers.id).get());

        let query;

        lastEvent
            ? (query = usersRef.where('birthday', '>=', today).startAfter(startAfter).limit(5))
            : (query = usersRef.where('birthday', '>=', today).limit(5))

            let querySnap = await query.get();

            if (querySnap.docs.length === 0) {
                console.log('querySnap.docs.length === 0');

                return querySnap;
            }

            let users = [];

            for (let i = 0; i < querySnap.docs.length; i++) {
                let user = {...querySnap.docs[i].data(), id: querySnap.docs[i].id}
                users.push(user)
            }

    console.log(users)                

            return querySnap;

    }
    catch (error) {
        console.log(error);

}

} `

devnoot commented 4 years ago

Were you ever able to figure this out? I'm running into the same issues

Franco-Alejandro commented 4 years ago

I think it says on the description that it isn't possible

Franco-Alejandro commented 4 years ago

The only well-supported type of compound query is where. A geoquery combines multiple smaller queries into a unified radius, so limit and pagination operators will not provide predictable results - a better approach is to search a smaller radius and do your sorting client-side.

So, no...

georgeMorales commented 4 years ago

No, it is not possible ... I changed to geofirestore, another library that allows to have a limit, although it is not possible to implement pagination either.