简体   繁体   English

Firestore 查询文档以特定字符开头

[英]Firestore query documents startsWith a specific character

Is it possible to query a firestore collection to get all document that starts with a specific character?是否可以查询 firestore 集合以获取所有以特定字符开头的文档? For example if I have a collection "Items" that contains:例如,如果我有一个集合“Items”,其中包含:

在此处输入图像描述

I want for example only the document starting with II don't know how modify the query, the method charAt[0] is not recognized:例如,我只想以 II 开头的文档不知道如何修改查询,方法 charAt[0] 无法识别:

return itemRef
      .doc(this.itemsId)
      .collection("october")
      .where(firebase.firestore.FieldPath.documentId().charAt[0], "==", randomChar)

From the top of my head, if interested in the letter "I":从我的头顶,如果对字母“I”感兴趣:

var lower = 'I';
var upper = String.fromCharCode(lower.codeUnitAt(0) + 1);

itemRef
      .doc(this.itemsId)
      .collection("october")
      .where(firebase.firestore.FieldPath.documentId() ">=", lower)
      .where(firebase.firestore.FieldPath.documentId() "<", upper)

Not sure, what happens in case of the letter Z.不确定,在字母 Z 的情况下会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM