Firestore:将值添加到集合中,并将另一个值添加到该新集合的字段中

时间:2018-12-17 22:55:22

标签: javascript firebase google-cloud-firestore

如何将“文本”作为集合添加到“ radioMedia”(电视节目/电影)文档中,然后将“ radioAmount”作为字段添加到“文本”集合中?

    var radioAmount;
    if(document.getElementById('smallPromo').checked) {
        radioAmount = 500;
    } else if (document.getElementById('largePromo').checked) {
        radioAmount = 1000;
    }

    var radioMedia;
    if(document.getElementById('show').checked) {
        radioMedia = "TV Shows";
    }
    else if (document.getElementById('movie').checked) {
        radioMedia = "Movies";
    }

    var text = document.getElementById('textSearch').value;

    firebase.firestore().collection('Promoted Media').doc(radioMedia).set({

        amount: radioAmount,
        name: text

    });

我在这里仅将“ radioAmount”和“ text”作为字段添加到radioMedia文档中

1 个答案:

答案 0 :(得分:0)

您将document添加到集合中。 document可以定义为普通对象,例如:

var myObj = {};
myObj.name = "John";
myObj.age = 21;

然后firebase.firestore.collection("people").doc().set(myObj);

您还可以在文档中添加sub-collection

相关问题