Вопросы

Облачные функции 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)
Читать:
Невозможно изменить переменную загрузки во Flutter

Похожие записи

Доступ для локальной разработки к конфигурации приложения Azure с управляемым удостоверением

admin

Перенаправление Trigger Stripe SCA для аутентификации

admin

Требуется добавить пользователя сразу во все командные проекты

admin

реагировать на собственный логин, api, jwt, auth, базовый

admin

Невозможно привязать данные к таблице данных материалов Angular

admin

Snapchat Login Kit не может выполнить перенаправление в мое приложение

admin