I have one problem regarding mapping values from mongodb from document having values (_id,author,title,content) representing one blog, to angular class with fields id,author,title,content; namely, using pipe and map operators in angular i can map the blog document, but without _id field from mongodb.

I thought i figured out how pipe and map works, but in my case I have one observable object which should be return, which complicates things for me. I read some documentation on https://angular.io/guide/rx-library but haven't quite figured out how to apply that in my case.

getBlogs(username): Observable<Blog[]> {
    return this.http.get(`${this.uri}/getBlogs/${username}`).pipe(
      map ((data: Blog[]) => {
        this.blogs = data;
        return this.blogs;
      }
    ));
}

Here in the code, I am trying to return all blogs belonging to one user with its username, and here I am mapping (i guess) all fields of data-mongodb documents with corresponding fields of blog. But all fields get mapped except id field (with Object_id field of mongodb).

My blog class look like:

export class Blog {

  id: string;
  author: string;
  title: string;
  content: string;

  public constructor() {}
}

I would greatly appreciate if anyone knows how can i resolve this.I am using mongodb 3.2 , angular cli 7.3.8 and angular 7.2.14.

0 Answers