Find a record through HorizonIO in RethinkDB without returning a result

I have a MeetingService that retrieves data from my RethinkDB through HorizonIO. When I try to get a meeting through my identifier, I always get a zero value as an answer. Other methods in this service work without problems.

meeting.service.ts:

getMeetingById(passedId: string): Observable<Meeting[]> { return this.table.find({meetingId: passedId}).fetch(); } 

conference detail.component.ts:

 currentMeeting: Meeting; getCurrentMeeting(): void { this._meetingsService.getMeetingById(this.passedId).subscribe( (returnMeetings: Meeting[]) => { this.currentMeeting = returnMeetings[0]; } ); } 

Even when I change passId to ID, I got directly from my db (through the admin panel), the method still returns null.

If I changed the code to return the first value in the table, everything will work.

 getMeetingById(passedId: string): Observable<Meeting[]> { return this.table.order("meetingId", "descending").limit(1).fetch(); } 

The end result is an undefined error in currentMeeting var in my view:

 EXCEPTION: Error in ./MeetingDetailComponent class MeetingDetailComponent - inline template:1:4 caused by: Cannot read property 'meetingId' of undefined 

Edit: additional code showing various implementations:

 load() { if(this.passedId != null) { this._feedService.GetFeedById(this.passedId).subscribe( (returnFeed: Feed[]) => { this.currentFeed = returnFeed[0]; } ); } else { this._feedService.GetFirstFeed().subscribe( (returnFeed: Feed[]) => { this.currentFeed = returnFeed[0]; } ); } } 

The second one works, firstly, no. The past identifier is correct and also available in the database, so this is rather confusing.

Thanks in advance.

+6
source share
1 answer

Although no one cares about this question, I found an answer that works relatively well. My temporary fix included collecting the entire table and manually searching for the correct identifier for each of them, but it’s also possible:

  • Create a variable that should be visible to the table (via .watch ())
  • Call flatMap () and get the observable array (if anyone knows why this is necessary, let me know)
  • Use find () and lambda to call the correct identifier.

     getMeetingById(passedId: string): Observable<IMeeting> { var allMeetings: Observable<Meeting[]>; allMeetings = this.table.watch(); return allMeetings.flatMap((meetings: IMeeting[]) => Observable.from(meetings)) .find((meeting: IMeeting) => (meeting.id == passedId)); } 
+3
source

Source: https://habr.com/ru/post/1015621/


All Articles