Облачные функции firebase ограничивают детей

Спасибо. Я развертываю функцию для ограничения дочерних узлов, сгенерированных командой push. Я перехожу по ссылке код для ограничения дочернего узла Теперь я просто редактирую этот код, помещая свой собственный код по следующей ссылке:

    'use strict';

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

// Max number of lines of the chat history.
const MAX_LOG_COUNT = 1;

// Removes siblings of the node that element that triggered the function if there are more than MAX_LOG_COUNT.
// In this example we'll keep the max number of chat message history to MAX_LOG_COUNT.
exports.truncate = functions.database.ref('/grid/{pushId}').onWrite((change) => {
  const parentRef = change.after.ref.parent;
  return parentRef.once('value').then((snapshot) => {
    if (snapshot.numChildren() >= MAX_LOG_COUNT) {
      let childCount = 0;
      const updates = {};
      snapshot.forEach((child) => {
        if (++childCount <= snapshot.numChildren() - MAX_LOG_COUNT) {
          updates[child.key] = null;
        }
      });
      // Update the parent. This effectively removes the extra children.
      return parentRef.update(updates);
    }
    return null;
  });
});

Итак, здесь я развертываю функции для ограничения детей, но получаю ошибку в журналах firebase как:

TypeError: Cannot read property 'ref' of undefined
    at exports.truncate.functions.database.ref.onWrite (/user_code/index.js:11:33)
    at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27)
    at next (native)
    at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
    at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
    at /var/tmp/worker/worker.js:700:26
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

См. также:  В Nuxtjs динамические страницы css и js не загружаются при перезагрузке страницы
Понравилась статья? Поделиться с друзьями:
IT Шеф
Комментарии: 1
  1. Disha Karnataki

    Не уверен, что это еще нужно. Вы инициализировали приложение Firebase? Добавьте следующие строки, если они еще не добавлены, и проверьте еще раз.

    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp(functions.config().firebase);
    
    //Define your trigger
    
Добавить комментарий

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: