简体   繁体   中英

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?

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

I understand that you want to get a maximum of 6 "sibling" posts. You could make the same query, with a limit of 7 docs and, in your front-end , filter the result:

By looping over the list of docs and compare their Id to the current doc Id you will encounter two cases:

  1. The current doc is within the 7 docs returned by the query: remove it from the list
  2. The current doc is NOT within the 7 docs returned by the query: remove one doc randomly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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