小编Sj *_*aza的帖子

如何从 Cloud Firestore 数据库获取 node.js 中的特定字段值?

如何在节点js中获取那个token_id?

数据库图像

X

Index.js 代码如下,通过此代码,它提供了存储在 user_id 中的所有数据,但我无法仅获取 {token_id} 的特定字段。

const functions = require('firebase-functions');

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

var db = admin.firestore();

exports.sendoNotification = functions.firestore.document('/Users/{user_id}/Notification/{notification_id}').onWrite((change, context) => {


  const user_id = context.params.user_id;
  const notification_id = context.params.notification_id;

  console.log('We have a notification from : ', user_id);
  
  
var cityRef = db.collection('Users').doc(user_id);
var getDoc = cityRef.get()
    .then(doc => {
      if (!doc.exists) {
        console.log('No such document!');
      } else {
        console.log('Document data:', doc.data());
      }
    })
    .catch(err => {
      console.log('Error getting document', err);

		return Promise.all([getDoc]).then(result => {



			const …
Run Code Online (Sandbox Code Playgroud)

push-notification node.js firebase google-cloud-functions google-cloud-firestore

7
推荐指数
1
解决办法
5730
查看次数