0

I'm using AngularFire 2, a Firestore database and Angular5/6. I want to search a string, nested in collections and documents and get the parent-document.

Let's say I want to search the message "Hello World!", which is nested in

rooms > roomA > messages > message1.msg

and then get back the name of the chatroom roomA.name = "my chat room"

Is that even possible? Because I don't know which room even contains the message "Hello World!". It can be roomA / roomB, so no defined document... Also: I don't know which message contains the "Hello World".

So the path would look like rooms/*/messages/*.msg ? But how can I do a query on a path like that?

let query = afs.collection('rooms', ref => ref.where('???', '==', 'Hello World!')).valueChanges();

enter image description here

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Taremeh
  • 302
  • 2
  • 4
  • 13
  • Firestore queries are restricted to a single colleciton. If the messages for each room are in a subcollection of that room, you can't search for messages across rooms. See https://stackoverflow.com/questions/46573014/firestore-query-subcollections – Frank van Puffelen May 06 '18 at 13:33

1 Answers1

0

It should be something like,

this.afs.collection('rooms', ref => ref .where(roomA.messages.message1,'==','Hello World!')).valueChanges() 
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396