GoogleCloudPlatform / node-red-contrib-google-cloud

Node-RED nodes for Google Cloud Platform
Apache License 2.0
90 stars 57 forks source link

Firestore: create document with an autogenerated id #105

Open Albert-Alvarez opened 2 years ago

Albert-Alvarez commented 2 years ago

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.

camow7 commented 1 year ago

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.