I have a following collections
-likes (collection)
-{uid} (document)
{otheruserUID: true, anotherUID: true ...}
-likedBy (collection)
-{uid} (document)
{otheruserUID: true, anotherUID: true ...}
A user can like other users. What I want to query for is given a user, query for all matches of that user. Should I query whole likes and likedby data and run match in result and produce match results? Is there any other easy way to do this? Or may be better way to model the data?
Personally, I would simply have a single collection, called
likes
. Each like generates a new document with an auto-id and contains 3 fields:user
(an object containing theid
andname
of the user),likedBy
(an object containing theid
andname
of the user who liked them) andtimestamp
(when they were liked).You'll be able to carry out the following queries:
The first time that you run these queries, you will get an error, telling you to create an index. This error will include the URL to create the index for you.
The first
where
is required to allow theorderBy
to work, see the documentation section Range filter and orderBy on the same field