为什么Firestore文档没有创建或更新数据?

时间:2019-09-01 00:05:01

标签: node.js google-cloud-firestore

问题

Firestore文档未创建或更新数据

admin.initializeApp();

let db = admin.firestore()
let user = db.collection('users').doc(userId);
let data = {
    timestamp: FieldValue.serverTimestamp(),
        bounties : {
            [impressionId] : {
                timestamp: timestamp,
                amount: amount,
                currency: currency
        }
    }
};

user.set(data, {merge: true});

期望

以下示例数据应用于创建或更新Cloud Firestore文档

{
   "example-user-1": {
        "bounties": {
               "example-impression-1": {
                    "timestamp": "12315443",
                    "amount": 0.0,
                    "currency": "null"
               }
         }
   }
}

结果

未创建文档

2 个答案:

答案 0 :(得分:0)

选项1

安装此库并添加此代码后,它可以工作!但我不知道为什么。

list.setOnItemLongClickListener(new OnItemLongClickListener() { //list is my listView

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                final int pos, long id) {
        //Whatever you wanna do
            ClipboardManager clipboard = (ClipboardManager) 
            getSystemService(Context.CLIPBOARD_SERVICE); 
            ClipData clip = ClipData.newPlainText(label, text);
            clipboard.setPrimaryClip(clip);
        }
});

答案 1 :(得分:0)

user.set(data, {merge: true}).then(data=>{console.log(data)});