niclas_4
niclas_4

Reputation: 3674

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?

Upvotes: 0

Views: 38

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83093

Firestore doesn't provide the possibility to query with inequality (i.e. 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.

Upvotes: 1

Related Questions