GoogleCloudPlatform/node-red-contrib-google-cloud

Firestore: create document with an autogenerated id

Opened this issue · 1 comments

How can I create a document inside a (sub)collection without indicate an id to allow Firestore to create an autogenerated one?

Thx in advance.

You can control this yourself. For example I use a function node to create the object ID based on timestamps.

var d = new Date();

let newMsg = {
    payload: {
        content: {
            distance: msg.payload
        },
        path: `collection_name/${d.getTime()}`
    }
} 
return newMsg;

You could just change the timestamp to a random GUID you generate.