firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Firestore Emulator different behavior in the Emulator and Cloud with OrderBy

Open MorenoMdz opened this issue 3 years ago • 3 comments

[REQUIRED] Environment info

firebase-tools: 11.1.0

Platform: MacOs

[REQUIRED] Test case

The code below does not error locally with the emulator, but errors when targeting the cloud db.

  let baseQuery = db
    .collection('incentives')
    .where('startTime', '<=', new Date())
    .where('status', '==', IncentiveStatus.Active)
    .where('target', '==', target)
    .where('valueType', 'in', [
      ValueType.Cash,
      ValueType.HourlyRate,
      ValueType.Rate,
    ])
    .orderBy('startTime')

  if (shiftId) {
    baseQuery = baseQuery.where('shiftId', '==', shiftId)
  }
  if (shiftIncentivesOnly) {
    baseQuery = baseQuery.orderBy('shiftId') // this is being used to ONLY fetch documents that have this field
  }

  const ref = await baseQuery.withConverter(defaultConverter<Incentive>()).get()
  const startedIncentives = ref.docs.map((doc) => ({
    id: doc.id,
    ...doc.data(),
  }))
...

[REQUIRED] Expected behavior

Same errors in the emulator and in the cloud.

[REQUIRED] Actual behavior

The emulator accepts this query and responds correctly.

MorenoMdz avatar Jul 01 '22 21:07 MorenoMdz

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Jul 01 '22 21:07 google-oss-bot

@MorenoMdz What is the production error message exactly? If it is related to missing indexes, then you've run into #2027 where Firestore indexes must be explicitly created in production but not the emulator. If so, feel free to close this issue and subscribe / +1 there. If it is something else, please provide as much information about the error as possible.

yuchenshi avatar Jul 11 '22 20:07 yuchenshi

@MorenoMdz What is the production error message exactly? If it is related to missing indexes, then you've run into #2027 where Firestore indexes must be explicitly created in production but not the emulator. If so, feel free to close this issue and subscribe / +1 there. If it is something else, please provide as much information about the error as possible.

We could close this one, but looks like #2027 has many comments without much attention, we do need to have the same behavior in the emulator and the cloud db ideally.

MorenoMdz avatar Jul 11 '22 22:07 MorenoMdz

Closing this one as we are moving from Firestore to a different database.

MorenoMdz avatar Jan 17 '23 02:01 MorenoMdz