Skip to content

FR: Query in operator #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nitrag opened this issue Dec 8, 2017 · 6 comments
Closed

FR: Query in operator #549

nitrag opened this issue Dec 8, 2017 · 6 comments

Comments

@nitrag
Copy link

nitrag commented Dec 8, 2017

It would be really really nice if we could query this in this SDK. Currently I'm having to store room references in my /users/ Documents

Firestore Data Model for Chat app:

/users/
/users/{userId}/
/users/{userId}/rooms    (this is a DocumentReference Array of rooms)
/users/{userId}/first_name
/users/{userId}/last_name
/users/{userId}/last_active

/rooms/
/rooms/{roomId}/
/rooms/{roomId}/created
/rooms/{roomId}/last_updated
/rooms/{roomId}/users    (this is an String Array of userIds)
/rooms/{roomId}/messages/...

Server-side Rules:
allow read, write: if request.auth.uid in resource.data.users;

Proposed:
roomsRef.where("users", "in", currentUserId)

@wilhuff
Copy link
Contributor

wilhuff commented Jan 3, 2018

Thanks for writing in.

This is something we're looking at doing. Unfortunately I can't promise when it's going to happen, nor can I really promise if the design we land on will necessarily exactly match what you're asking for.

This specific use case (array of group members) is a specific requirement for adding this.

@wilhuff
Copy link
Contributor

wilhuff commented Mar 22, 2019

While we're still very interested in this feature, there's little value in tracking this separately for just iOS. The canonical issue for this is firebase/firebase-js-sdk#321. I'll close this one as a duplicate.

@wilhuff wilhuff closed this as completed Mar 22, 2019
@rockwotj
Copy link

@mikelehen
Copy link
Contributor

@wilhuff is OOO this week, but I think you're right @rockwotj. array-contains should solve @nitrag's use case!

@nitrag
Copy link
Author

nitrag commented Apr 4, 2019

I had been using this, do I need the get() if the match is already for the same level object?

service cloud.firestore {
  match /databases/{database}/documents {
    match /rooms/{roomId} {
      allow read, write: if request.auth.uid in get(/databases/$(database)/documents/rooms/$(roomId)).data.users;
      allow create: if request.auth != null;
    }
  }
}

@rockwotj
Copy link

rockwotj commented Apr 4, 2019

You can't use {roomId} for queries in rules because we don't know what document IDs that will be returned at the time of rules evaluation.

For queries we populate the resource property with the minimal document guaranteed to be returned by all query results.

You want this rule:

allow read, write: if request.auth.uid in resource.data.users

@firebase firebase locked and limited conversation to collaborators Nov 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants