1

This listener works great:

firebase.firestore().collection('Users').doc($scope.user.uid).collection('Spanish').doc('Word_Response').onSnapshot(function(wordResponse) {

But we have more languages than Spanish. This listener doesn't work:

firebase.firestore().collection('Users').doc($scope.user.uid).collection($scope.longLanguage).doc('Word_Response').onSnapshot(function(wordResponse) {

$scope.longLanguage is set to American_English when the app loads and the listener starts listening. The user can switch to Spanish, Mandarin, Finnish, etc., which changes $scope.longLanguage. The problem is that in the listener the variable $scope.longLanguage doesn't change. Can we change the collection on the fly, or do we have to write listeners for every language, i.e., for every collection?

The documentation says that we can listen to multiple documents in a collection (using the where filter) but doesn't say that we can listen to multiple collections.

Thomas David Kehoe
  • 10,040
  • 14
  • 61
  • 100

1 Answers1

2

You currently can't have a query span collections, neither top-level collections, nor subcollections. If you need to query across collections, there needs to be one query for each collection, and you have to merge the results of the queries in the client.

See also Firestore query subcollections

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441