Can't seem to get combineAll() working

26 views
Skip to first unread message

Christopher de Vidal

unread,
Mar 3, 2020, 2:45:31 PM3/3/20
to Angular and AngularJS discussion
Help a newbie? The Firebase Firestore users/<user> collection contains a serials subcollection that I assign to serials$. Each one of those fields is turned into a string for a query of the 'serials' collection in Firestore. But nothing is logging to the console. Please assist.

Schema:
/users/<username>/serials/['ABC123','ABC124','ABC125']
/serials/ABC123/friendly_name = 'Near the house'
/serials/ABC124/friendly_name = 'Side yard'

  constructor(private afs: AngularFirestore) {

   
const serialsDocument = afs.doc<Serial>('users/cdevidal');
   
const serials$ = serialsDocument.collection<Serial>('serials').valueChanges();
   
const friendly_names$ = serials$.pipe(
      map
(serial_record => {
        console
.log('typeof serial_record: ');
        console
.log(typeof serial_record);
        console
.log('serial_record: ');
        console
.log(serial_record);
       
return afs.doc<FriendlyName>('serials/' + serial_record['serial']).valueChanges()
     
})
   
);
    friendly_names$
.pipe(combineAll()).subscribe(friendly_names_records => {
      console
.log('typeof friendly_names_records: ');
      console
.log(typeof friendly_names_records);
      console
.log('friendly_names_records: ');
      console
.log(friendly_names_records);
   
});
 
}


typeof serial_record:
object
serial_record
:
(3) [{…}, {…}, {…}]
0: {serial: "ABC125"}
1: {serial: "ABC124"}
2: {serial: "ABC123"}
length
: 3__proto__: Array(0)

Christopher de Vidal

unread,
Mar 3, 2020, 4:29:59 PM3/3/20
to Angular and AngularJS discussion
I worked around the problem by denormalizing but I'm curious if someone has thoughts how it might have been solved originally.

New schema:
/users/<username>/ABC123/name = 'Near the house'

On Tuesday, March 3, 2020 at 2:45:31 PM UTC-5, Christopher de Vidal wrote:
Help a newbie? The Firebase Firestore users/<user> collection contains a serials subcollection that I assign to serials$. Each one of those fields is turned into a string for a query of the 'serials' collection in Firestore. But nothing is logging to the console. Please assist.

Schema:
/users/<username>/serials = ['ABC123','ABC124','ABC125']

Arnaud Deman

unread,
Mar 4, 2020, 3:31:53 AM3/4/20
to Angular and AngularJS discussion
Hi Christopher,

I think it is because the observables returned by AngularFirestore never complete.
You can use the take operator to make it complete manually.
Regards,
Arnaud.

Christopher de Vidal

unread,
Mar 6, 2020, 9:16:30 PM3/6/20
to Angular and AngularJS discussion
Thanks for your reply. I'm new, where would I place take()? 

Arnaud Deman

unread,
Mar 7, 2020, 7:21:43 AM3/7/20
to Angular and AngularJS discussion
Hi Christopher,

I am not completely sure. As the definition of combineAll is to apply combineAll when the observervable of observable complete I would say here :

return afs.doc<FriendlyName>('serials/' + serial_record['serial']).valueChanges().pipe(take(1))

Regards,
Arnaud.

Arnaud Deman

unread,
Mar 7, 2020, 11:07:03 AM3/7/20
to Angular and AngularJS discussion

Sorry for the typo : combineAll apply combineLatest when the observable of observable completes.
Reply all
Reply to author
Forward
0 new messages