• Resolved webwurm

    (@webwurm)


    I know it is a very specific problem, but I am trying figuring this out for 2 days now – and I can’t. Maybe somebody can help. It’s about creating a shortcode, that gives information from one specific firestore-field back. But here the details:

    My Firestore:

    Links-coll.
    |
    *-- link_id [String]
    |
    *-- object_ref [Reference to Objekte-collection-document]
    
    Objekte-coll.
    |
    *-- name [String]
    

    My aim:
    1. Find the document in Links, where the field “link_id” matches a given string
    2. Show the name of the object from the Objekte-collection to which the “objekt_ref”-field in the Links-collection points to.

    What I came up with so far:

    function getObjectIdFromLinkId(linkId) {
    	const showFirestoreDatabase = () => {
        	const db = firebase.firestore();
    
    		db.collection("Links")
    			.where("link_id", "==", linkId)
        		.get()
        		.then((querySnapshot) => {
            		querySnapshot.forEach((doc) => { 
    					// there should be only one
    					// in the field "object_ref" is the reference to another collection/document
    					var docRef = db.doc(doc.data().object_ref);
    					docRef.get().then((doc) => {
        					if (doc.exists) {
            					console.log("Document data:", doc.data());
        					} else {
            					console.log("No such document!");
        					}
    					})
    					.catch((error) => {
        					console.log("Error getting Object-document:", error);
    					});
            		});
        		})
        		.catch((error) => {
            		console.log("Error getting Link-documents: ", error);
        		});
    	}
    
    	const waitForFirebase = setInterval(() => {
    	if (typeof firebase !== 'undefined' && firebase.apps.length) {
            	showFirestoreDatabase()
            	clearInterval(waitForFirebase)
        	}
    	}, 1000)
    }

    Like this I get the error “TypeError: n.indexOf is not a function”

    I would be really happy if somebody could help.
    Thanks a lot in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help getting firestore-information’ is closed to new replies.