import { initializeApp } from "npm:firebase@9.20.0/app";
import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
/**
* Overwrites or updates a document.
*
* @param document_path Path to the document.
* If you want to update a top-level document by ID, pass in an array with only
* the ID in it.
* *eg:* `[ 'my-id' ]`
*
* @param merge If `true`, the document will be updated with provided fields,
* otherwise the document will be completely overwritten.
* **WARNING:** Overwriting a document may result in data loss.
*
* @param mergeFields Controls which fields should be merged.
*/
type Firebase = {
apiKey: string;
authDomain: string;
projectId: string;
storageBucket: string;
messagingSenderId: string;
appId: string;
measurementId: string;
};
export async function main(
auth: Firebase,
collection_id: string,
document_path: string[],
document: Record<string, any>,
merge?: boolean,
mergeFields?: string[],
) {
const app = initializeApp(auth);
const store = getFirestore(app);
const docRef = doc(store, collection_id, ...document_path);
await setDoc(docRef, document, {
merge: typeof merge === "boolean" ? merge : undefined,
mergeFields:
Array.isArray(mergeFields) && mergeFields.length
? mergeFields
: undefined,
});
}
Submitted by admin 497 days ago
import { initializeApp } from "npm:firebase@9.20.0/app";
import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
/**
* Overwrites or updates a document.
*
* @param document_path Path to the document.
* If you want to update a top-level document by ID, pass in an array with only
* the ID in it.
* *eg:* `[ 'my-id' ]`
*
* @param merge If `true`, the document will be updated with provided fields,
* otherwise the document will be completely overwritten.
* **WARNING:** Overwriting a document may result in data loss.
*
* @param mergeFields Controls which fields should be merged.
*/
type Firebase = {
apiKey: string;
authDomain: string;
projectId: string;
storageBucket: string;
messagingSenderId: string;
appId: string;
measurementId: string;
};
export async function main(
auth: Firebase,
collection_id: string,
document_path: string[],
document: Record<string, any>,
merge?: boolean,
mergeFields?: string[],
) {
const app = initializeApp(auth);
const store = getFirestore(app);
const docRef = doc(store, collection_id, ...document_path);
await setDoc(docRef, document, {
merge: typeof merge === "boolean" ? merge : undefined,
mergeFields: Array.isArray(mergeFields) && mergeFields.length
? mergeFields
: undefined,
});
}
Submitted by admin 501 days ago
import { Resource } from "https://deno.land/x/windmill@v1.89.0/mod.ts";
import { initializeApp } from "npm:firebase@9.20.0/app";
import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
/**
* Overwrites or updates a document.
*
* @param document_path Path to the document.
* If you want to update a top-level document by ID, pass in an array with only
* the ID in it.
* *eg:* `[ 'my-id' ]`
*
* @param merge If `true`, the document will be updated with provided fields,
* otherwise the document will be completely overwritten.
* **WARNING:** Overwriting a document may result in data loss.
*
* @param mergeFields Controls which fields should be merged.
*/
export async function main(
auth: Resource<"firebase">,
collection_id: string,
document_path: string[],
document: Record<string, any>,
merge?: boolean,
mergeFields?: string[],
) {
const app = initializeApp(auth);
const store = getFirestore(app);
const docRef = doc(store, collection_id, ...document_path);
await setDoc(docRef, document, {
merge: typeof merge === "boolean" ? merge : undefined,
mergeFields: Array.isArray(mergeFields) && mergeFields.length
? mergeFields
: undefined,
});
}
Submitted by adam186 606 days ago
import { Resource } from "https://deno.land/x/windmill@v1.89.0/mod.ts";
import { initializeApp } from "npm:firebase@9.20.0/app";
import { doc, getFirestore, setDoc } from "npm:firebase/firestore/lite";
/**
* Overwrites or updates a document.
*
* @param document_path Path to the document.
* If you want to update a top-level document by ID, pass in an array with only
* the ID in it.
* *eg:* `[ 'my-id' ]`
*
* @param merge If `true`, the document will be updated with provided fields,
* otherwise the document will be completely overwritten.
* **WARNING:** Overwriting a document may result in data loss.
*
* @param mergeFields Controls which fields should be merged.
*
* @returns The ID of the document that was attempted to update.
*/
export async function main(
auth: Resource<"firebase">,
collection_id: string,
document_path: string[],
document: Record<string, any>,
merge?: boolean,
mergeFields?: string[],
) {
const app = initializeApp(auth);
const store = getFirestore(app);
const docRef = doc(store, collection_id, ...document_path);
await setDoc(docRef, document, {
merge: typeof merge === "boolean" ? merge : undefined,
mergeFields: Array.isArray(mergeFields) && mergeFields.length
? mergeFields
: undefined,
});
}
Submitted by adam186 606 days ago