简体   繁体   English

在Firestore中忽略DocID

[英]Ignoring DocID in Firestore

I have a simple Query which is there to recommend Users under a Post related Posts. 我有一个简单的查询,可以在与帖子相关的帖子下向用户推荐。

await this.$fireStore.collection('posts')
.limit(6).where('tags', 'array-contains', this.post.tags[0]).get().then(querySnapshot => {

Problem is that this also Reads out the Post itself (since it contains the Tag too), is there any way to query for Posts that dont have a specific DocID without wasting a Where ergo needing a complete new Query? 问题在于,这也会读取帖子本身(因为它也包含标签),有没有办法查询没有特定DocID的帖子而又不会浪费Where ergo需要一个完整的新查询?

Firestore doesn't provide the possibility to query with inequality (ie not equals), see for example this SO post: Firestore: how to perform a query with inequality / not equals Firestore无法提供不相等查询(即不等于)的可能性,例如参见以下SO文章: Firestore:如何执行不相等查询/不等于查询

I understand that you want to get a maximum of 6 "sibling" posts. 我了解您最多希望获得6个“同级”职位。 You could make the same query, with a limit of 7 docs and, in your front-end , filter the result: 您可以进行相同的查询,最多7个文档,并在前端过滤结果:

By looping over the list of docs and compare their Id to the current doc Id you will encounter two cases: 通过遍历文档列表并将其ID与当前文档ID进行比较,您会遇到两种情况:

  1. The current doc is within the 7 docs returned by the query: remove it from the list 当前文档位于查询返回的7个文档中:将其从列表中删除
  2. The current doc is NOT within the 7 docs returned by the query: remove one doc randomly. 当前文档不在查询返回的7个文档之内:随机删除一个文档。

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

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