0

I return to this question.

I have the following structure. Each user has his own data.

---+ FB_ROOT_REFERENCE
   |
   +---+ Gy7FXRbRjDfAKWu7a95NgiGIZUk1  (Firebase User Id)
       |
       |
       +---+ KlNlb71qtQUXIGA4cNa (random key, generated by Firebase)
       |   |
       |   +--- (data field ...)
       |
       |
       +---+ KlNlcmfMTDjxQ0BwW1K
       |   |
       |   +--- (data field ...)
       |
       +---+ (...)

I've made some changes to the source code, but I do not know where to move next.

// Max number of lines
const MAX_RECORD_COUNT = 5;
const FB_ROOT_REFERENCE = '/locations';
// Removes siblings of the node that element that triggered the function if there are more than MAX_RECORD_COUNT.
// In this example we'll keep the max number of chat message history to MAX_RECORD_COUNT.
exports.truncate = functions.https.onRequest((req, res) => {

    const cron_key = req.query.key;

    // Exit if the keys don't match
      if (!secureCompare(cron_key, functions.config().cron.key)) {
        console.log('The cron_key provided in the request does not match the cron_key set in the environment. Check that', cron_key,
            'matches the cron.key attribute in `firebase env:get`');
        res.status(403).send('Security cron_key does not match. Make sure your cron_key URL query parameter matches the ' +
            'cron.key environment variable.');
        return;
      }

// Next
// need iterate all the children in (FB_ROOT_REFERENCE + user id)
// and keep MAX_RECORD_COUNT data children
// most recent and delete all the rest (older ones)
// ... 
// Here your code is required....

});

I would be very grateful if anyone could help me to write the source code. Thank you.

The code in this example will probably be useful "Limit number of child nodes"

tim4dev
  • 2,846
  • 2
  • 24
  • 30

0 Answers0