Skip to content
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

Feature request: support array-contains #1809

Closed
davidtlee opened this issue Aug 9, 2018 · 10 comments
Closed

Feature request: support array-contains #1809

davidtlee opened this issue Aug 9, 2018 · 10 comments

Comments

@davidtlee
Copy link

It looks like firestore now supports array_contains query functionality:

https://firebase.google.com/support/release-notes/js

image

This would be super useful for reducing the querying needed. For example if I need to get all the comments for a list of N posts, this would N individual queries. With array-contains, you could get them all in one query!

@davideast
Copy link
Member

Hi @davidtlee! We support this already in the query callback.

@Matttaylor8910
Copy link

Hi @davideast, could you give an example or point to documentation?

Using 'array-contains' within the where clause throws the following error:

[ts] Argument of type '"array-contains"' is not assignable to parameter of type 'WhereFilterOp'.

This is the code I'm trying to use with version 5.0.0-rc.11 of angularfire2:
return this.afs.collection('games', ref => { return ref .orderBy('timestamp') .where('playerIds', 'array-contains', uid) .limit(30); })

@leonlovett
Copy link

leonlovett commented Aug 12, 2018

@Matttaylor8910 I had the same issue. Searching does work as David East says, but for some reason the typings weren't correct for me locally. I had to edit the typings file for firebase, then the app started building again.

Open node_modules/firebase/index.d.ts to line 1543 and added 'array-contains' to the type WhereFilterOp.

image

@davidtlee
Copy link
Author

@davideast thanks! it does look like it works. But I realized I was reading it wrong. I thought array-contains allows passing in an array for matching anything within the array. But I realized it only allows passing in a single value and checking if an array on the backend contains the query item. whoops!

@davideast
Copy link
Member

@leonlovett If you update to the latest Firebase version the typings should work

@gtcdevop
Copy link

gtcdevop commented Aug 14, 2018

I manage to solve this issue using the following dependencies version

{
// all Angular deps on version 5.0.3
...
 "angularfire2": "5.0.0-rc.6",
 "rxjs": "5.5.4",
 "firebase": "5.3.0",
 "@firebase/app": "0.1.10",
...
}

@yogeshdakre
Copy link

yogeshdakre commented Aug 31, 2018

array-contains only work with string?? the examples which are given shows that it works with string but how to deal when array contains objects
/mycollection
/array +{name:'yogi'},
{name:'yogi1'},
{name:'yogi2'}

here how the query will be for object with name==yogi?
this.afs
.collection('userroutes', ref =>
{ return ref.where('mycollection','array-contains','name==yogi') } //where we should put the condtion
)
.valueChanges()
.subscribe(data => {
//data is empty
});

@hiepxanh
Copy link
Contributor

hiepxanh commented Oct 24, 2018

Hi everyone, I just find out that a little different here: array-contains and array_contains
image
should we update this for consistance @davideast

@jek-bao-choo
Copy link
Contributor

@hiepxanh for consistency, I think we should update this to array_contains.

@IchordeDionysos
Copy link

array-contains is indeed consistent across platforms only the Python SDK seems to use the underscore version and as well in the docs it's everywhere mentioned with an underscore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants