-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (22 loc) · 710 Bytes
/
index.js
File metadata and controls
23 lines (22 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Triggered from a message on a Cloud Pub/Sub topic.
*
* @param {!Object} event Event payload.
* @param {!Object} context Metadata for the event.
*/
exports.migratePubSub = async (event, context) => {
const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
const collectionName = 'example-collection';
if(event.data) {
const message = JSON.parse(Buffer.from(event.data, 'base64').toString());
const doc = firestore.collection(collectionName).doc(`${message.id}`);
if(!message._delete)
await doc.set(message, {merge: true});
else
await doc.delete();
console.log(message);
} else {
console.log('empty message');
}
};