Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get one document by ID Angular 4 + Firestore

How to make it work okay? I need only one document from base with id.Is it possible to subscribe it? Because it returns me a Observable object:(

Here`s my code.

getByid(id){
  return this.itemscollection.doc('9K6ue-afwwafwaf').valueChanges();
  }
like image 284
Kek Testerov Avatar asked Jan 30 '23 06:01

Kek Testerov


1 Answers

I think you are trying to do this:

constructor(db: AngularFirestore){
db.collection('yourcollection').doc("documentid").ref.get().then(function (doc) {
  if (doc.exists) {
    console.log(doc.data());
  } else {
    console.log("There is no document!");
  }
}).catch(function (error) {
  console.log("There was an error getting your document:", error);
});}

The above is the simplest way I know to read a document on firestore. It will show the internal data from your document. I hope it helps to you.

like image 128
Carlos Moya Avatar answered Feb 07 '23 10:02

Carlos Moya