Skip to content

where does "db" come from? #265

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
carcinocron opened this issue Jan 22, 2022 · 1 comment
Open

where does "db" come from? #265

carcinocron opened this issue Jan 22, 2022 · 1 comment

Comments

@carcinocron
Copy link

Almost all the docs do this, I have no idea where "db" came from. I'm also not sure if I should be using web9 or nodejs, but it's often a lot of samples are missing one or both, or are less clearly labeled.

import { runTransaction } from "firebase/firestore";
try {
await runTransaction(db, async (transaction) => {
const sfDoc = await transaction.get(sfDocRef);
if (!sfDoc.exists()) {
throw "Document does not exist!";
}
const newPopulation = sfDoc.data().population + 1;
transaction.update(sfDocRef, { population: newPopulation });
});
console.log("Transaction successfully committed!");
} catch (e) {
console.log("Transaction failed: ", e);
}

@Tim4497
Copy link

Tim4497 commented Jul 25, 2022

const firebaseConfig = {
  apiKey: 
  authDomain: 
  projectId: 
  storageBucket: 
  messagingSenderId: 
  appId: 
};

const app = initializeApp(firebaseConfig);

const db = getFirestore(app);

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants