Я отправляю данные из формы в мою базу данных. Как я правильно понял, использование .push () создает уникальный идентификатор, куда мои данные добавляются и загружаются. Теперь мне нужно получить те же данные, а затем добавить новую запись идентификатора. Но я не могу ссылаться на данные, поскольку они хранятся под уникальным идентификатором, созданным методом .push ().
exports.addUser = functions.https.onRequest(async (req, res) => { //Adds data from the form to the database
cors(req, res, async () => {
// Grab the message body parameter.
const entry = req.body;
// Push the new message into the Realtime Database using the Firebase Admin SDK.
const snapshot = await admin.database().ref('entries/users/').push(entry);
console.log('my new shiny id is ' + snapshot.key());
// Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
res.redirect(303, snapshot.ref.toString());
})
});
//Function to generate a random ID and update into the entry from the form on the database.
exports.generateID = functions.database.ref('entries/users/').onCreate((snapshot, context) => {
console.log(snapshot.val());
const original = snapshot.val();
console.log(context);
console.log(snapshot.key());
const dev = '0eeb94ca-3426-46ca-964d-a9bdd7d00ef0';
var random = Math.random().toString(36).substring(7);
const code = uuidv5('user-' + random, dev);
return snapshot.ref.update({
userID: code
});
})
Вот изображение структуры данных в моей базе данных реального времени.