如何将数据添加到Cloud Firestore? [英] How to add data to Cloud Firestore?

查看:83
本文介绍了如何将数据添加到Cloud Firestore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是未插入数据.

这是node.js代码:

Here is the node.js code :

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

var db = admin.firestore();
exports.signUp = functions.https.onCall((data, context) => {
  const uuid = data.uuid;
  const name = data.name;
  const gender = data.gender;
  const age = data.age;

  var docRef = db.collection('users').doc(uuid).set({
    name: name,
    gender: gender,
    age: age,
    current_point: 0,
    point_charging: 0,
    init_timestamp: admin.database.ServerValue.TIMESTAMP,
    update_timestamp: admin.database.ServerValue.TIMESTAMP
  }).then(function() {
    console.log("Document successfully written!");
    return;
  }).catch(function(error) {
    console.error("Error writing document: ", error);
    return;
  });
});

firebase函数的日志结果:

The log results of firebase functions :

但是,我的数据库仍然是空的.我找不到我的错.帮助.

However, my database is still empty. I can not find my fault. Help.

推荐答案

自我解答

Self Answer

我尝试通过移动设备上的firebase函数将数据插入到Firestore中,但我对其进行了修改,以将其直接插入移动设备中.通过函数插入数据...我不知道它是否行不通.

I tried to insert data into the firestore via firebase functions on mobile, but I modified it to insert it directly in mobile. Inserting data through functions ... I don't know if it will not work.

这篇关于如何将数据添加到Cloud Firestore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆