0

in firebase I want to sort the value of a certain field in descending order for a certain period of time and bring the data. I want to know how.

const currentTime = firebase.firestore.Timestamp.now();

const twentyFourHoursAgo = new firebase.firestore.Timestamp(currentTime.seconds - (24 * 60 * 60), currentTime.nanoseconds);

//   db.collection('product').where('Timestamp', '>', twentyFourHoursAgo).orderBy('Timestamp').orderBy('participantCount', 'desc').startAfter(lastVisibleDoc).limit(3).get().then((결과) => {}

I've tried this now, but it doesn't seem to work.

No error, but no data coming in

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • When you execute that query, check the console for a logged message containing a link to configure the required Firestore index for `Timestamp asc, participantCount desc`. Additionally, you can use `const twentyFourHoursAgo = firebase.firestore.Timestamp.fromMillis(Date.now() - (24 * 60 * 60 * 1000))`. – samthecodingman May 23 '23 at 05:01
  • db.collection('product').where('Timestamp', '>', twentyFourHoursAgo).orderBy('Timestamp').orderBy('participantCount', 'desc').get().then((결과) => {} Not OK. Filtering on timestamp seems to work, but Descending sorting by count is not possible. db.collection('product').where('Timestamp', '>', twentyFourHoursAgo).orderBy('Timestamp').get().then((결과) => {} it’s OK db.collection('product').orderBy('participantCount', 'desc').get().then((결과) => {} it’s OK – Jingu Seok May 23 '23 at 13:18

0 Answers0