Firebase使用where子句获取数据并按顺序返回。

huangapple go评论63阅读模式
英文:

Firebase get with where clause and order of data returned

问题

在数据返回时,结果的顺序将与查询的顺序(["51", "32", "23", "41"])相同吗?是否有相关的文档参考?我想知道哪些数据匹配文档 ID 51,哪些数据匹配文档 ID 32等。

英文:

I have below code in my cloud function. Firestore api call is made to retrieve data that matches a certain document id.

        await myClinics
          .where(FieldPath.documentId(), "in", ["51","32","23","41"])
          .get()
          .then((snapshots) => {
            snapshots.forEach((doc) => {
              // console.log(doc.data());
              
            });
          });

When data is returned, what will be the order of results? will it be of same order as the query (["51","32","23","41"])?
Is there a documentation reference relating to this?

I would like to know which data matches document ID 51 and which data matches document ID 32 etc..

This is more of a question.

答案1

得分: 0

文档将按照它们在索引中出现的顺序返回,而不是按照您在in子句中指定值的顺序返回。

如果您想要为文档51执行特定的代码,请在您的代码中检查doc.id的值。

英文:

The documents will be returned in the order in which they occur in the index, not in the order in which you specify the values in the in clause.

If you want to execute specific code for document 51, check the doc.id value in your code.

huangapple
  • 本文由 发表于 2023年5月10日 18:58:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定