0

In firestore i have a collection called things.

Each thing is owned by a user.
Each thing can be shared by the owner with other specified users.

the structure of thing looks something like

{
    id: "thing01",
    sharedWith: {
        "user1": true,
        "user2": true,
    },
    dtCreated: 3458973948
}

When I want to retrieve all thing objects that are shared with user1, ordered by dtCreated desc,

i can't do this without having to create an index on things.thing.user1
i.e. for every unique userid i have to create an index on the things collection.

Obviously this is not practical. The docs talk about using full text search for this, but this doesn't seem like a problem we would want to use full text search for.

Is there a different way i should be structuring the data to achieve what i want?
Is firestore just the wrong technology choice for this?
It's working very well for storing the thing objects themselves.

---- update ----

this question is not a real duplicate of Firestore: Working with nested single queries because the answer provided there is very specific to the OP's context.

w--
  • 6,427
  • 12
  • 54
  • 92
  • Possible duplicate of [Firestore: Working with nested single queries](https://stackoverflow.com/questions/46724996/firestore-working-with-nested-single-queries) – Alex Mounir Feb 05 '18 at 08:03
  • Have you checked out [Working with Arrays, Lists, and Sets](https://firebase.google.com/docs/firestore/solutions/arrays)? It covers your exact use case. You may want to change the values from `"user1": true` to `"user1": "thing01"` to allow for ordering when you run your queries. This is explained towards the bottom of the linked documentation. – Jason Berryman Feb 05 '18 at 15:09
  • @jason Berryman i did actually. 2 points why I was still looking for an alternative solution. that solution requires constantly updating all the values in the map on every save (if i'm doing `dtModified`, which is what i actually care about). It also doesn't solve how i order on another attribute. so say `thing` has an attribute `label` and i'd like to be able to sort by that as well. any other thoughts? – w-- Feb 05 '18 at 18:38
  • I have the same issue myself. The only solution to this (with Cloud Firestore) is to integrate it with Elasticsearch or Algolia. Unless someone else has a better solution. I'm sorry that I can't be any more help than what you have already identified. – Jason Berryman Feb 05 '18 at 22:34
  • thx. did you actually integrate with algolia or elasticsearch? Curious to know what your experience has been. – w-- Feb 07 '18 at 01:35

0 Answers0