xiaolingxiao
xiaolingxiao

Reputation: 4885

firestore < query mixed with orderBy Query

I am using firestore to query documents with compound queries, my code is:

    let query = firestore.collection( 'market' )
    let res = []
    let newChkPt = false

    // states
    query = query.where('deListTime', '==', false)
    query = query.where('tradeTime' , '==', false)
    query = query.where('expirationTime', '>', Date.now())

    // FIFO ordering
    query = query.orderBy('originationTime', 'desc')        
    query = query.limit(3)


    if (chkPt) {

        await query
            .startAfter(chkPt)
            .get()
            .then(snap => {
                snap.forEach(doc => {
                    res.push(doc.data());
                    newChkPt = doc.data()['originationTime']           
                })
            })
            .catch(e => { console.log(e); return false})

    } else {

        await query
            .get()
            .then(snap => {
                snap.forEach(doc => {
                    res.push(doc.data());
                    newChkPt = doc.data()['originationTime']           
                })
            })
            .catch(e => { console.log(e); return false})
    }

In the console I have every combination composite query indices possible specified amongst the fields deListTime, tradeTime, expirationTime, and originationTime. And yet this compound query I specified refuse to fetch data as intended. If I comment out

    query = query.orderBy('originationTime', 'desc')       

I get the data, and if I comment the '>' out whilst leaving everything else un-commmented:

    query = query.where('expirationTime', '>', now)

I also get the desired data. Is it the > that's messing it up?

The indexes:

enter image description here enter image description here

enter image description here

Upvotes: 0

Views: 87

Answers (1)

Mark Daniel III
Mark Daniel III

Reputation: 26

Are you initializing 'now' somewhere? Did you mean Date.now()?

Upvotes: 1

Related Questions