How to get a document from a collection based on a particular field in that document

别等时光非礼了梦想. 提交于 2020-01-24 21:36:28

问题


const docRef = firestore.collection("orders").document("")

I need to get the document "147OiRKFYKA3WAo5d5mk" if the field value is Admno:"11.11.1111"

here is my database

Thankyou for the help.


回答1:


This case is mentioned in the official Firestore documentation:

db.collection("orders").where("Admno", "==", "11.11.1111")
    .get()
    .then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
            console.log(doc.id, " => ", doc.data()); //here's your doc
        });
    })
    .catch(function(error) {
        console.log("Error getting documents: ", error);
    });

I strongly recommend reading the documentation if you're getting started with Firestore.



来源:https://stackoverflow.com/questions/48247511/how-to-get-a-document-from-a-collection-based-on-a-particular-field-in-that-docu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!