Skip to content

Instantly share code, notes, and snippets.

@markreale
markreale / live_updating.js
Last active May 28, 2019 12:31
Firestore - event listener for when the Collection in the database updates - allows for "Live Updates"
db.collection("[YOUR_COLLECTION]").onSnapshot(function(querySnapshot){
// Things to do whenever the Firestore database Snapshot updates
});
@markreale
markreale / deleting_firestore.js
Created May 28, 2019 12:27
Firestore - Deleting an entry (Document) from a Collection
db.collection("[YOUR_COLLECTION]").doc("[YOUR_DOCUMENT]").delete().then(function() {
console.log("Document successfully deleted!");
}).catch(function(error) {
console.error("Error removing document: ", error);
});
@markreale
markreale / creating_auto_entry.js
Created May 28, 2019 12:24
Firestore - Creating an entry (Document) with an auto-generated ID
db.collection("[YOUR_COLLECTION]").add({
[YOUR_PROPERTY]: "[YOUR_UPDATED_VALUE]"
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
@markreale
markreale / creating_custom_document.js
Created May 28, 2019 12:21
Firestore - Creating a new entry (Document in a Collection) with a custom Document ID
db.collection("[YOUR_COLLECTION]").doc("[YOUR_DOCUMENT]").set({
[YOUR_PROPERTY]: "[YOUR_UPDATED_VALUE]"
})
.then(function() {
console.log("Document successfully written!");
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
@markreale
markreale / updating_firestore.js
Last active May 28, 2019 12:07
Firestore - Updating data (Updating Documents in Collections)
return db.collection("[YOUR_COLLECTION]").doc("[YOUR_DOCUMENT]").update({
[YOUR_PROPERTY]: "[YOUR_UPDATED_VALUE]"
})
.then(function() {
console.log("Document successfully updated!");
})
.catch(function(error) {
console.error("Error updating document: ", error);
});
@markreale
markreale / reading_firestore.js
Created May 28, 2019 12:00
Firestore - Reading and Referencing Data
db.collection("things").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// Code for handling each entry returned from the database
// ID for each Document in the Collection can be referenced with: doc.id
// Data for each Document in the Collection can be referenced with: doc.data()
});
@markreale
markreale / firestore_config.html
Created May 28, 2019 11:46
Creating a configuration for Firebase Firestore in an HTML file
<!--
Access the Firebase tools you need
We are using the CDN here
You can change the version number (6.0.4) to whatever the latest version of Firebase is
You can put this content in the <head> of your HTML file, or just before the closing </body> tag -
- there is arguments for both approaches
-->
<script src="https://www.gstatic.com/firebasejs/6.0.4/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.0.4/firebase-firestore.js"></script>
<script>
@markreale
markreale / connect.html
Created September 7, 2013 14:55
Connecting a CSS file to an HTML web page
<!doctype html>
<html>
<head>
<!-- Tell your browser where the CSS Style sheet for this web page is -->
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Inside the <body> tag will be the content that appears in your browser window -->
@markreale
markreale / basics.html
Last active December 21, 2015 15:19
The most basics of the basics. Document declaration, html, head, and body tags, and some comments about what goes where.
<!doctype html>
<html>
<head>
<!-- Inside the <head> tag will be content about your web page, or links to other resources. -->
</head>
<body>
<!-- Inside the <body> tag will be the content that appears in your browser window -->
</body>
@markreale
markreale / og.html
Created June 3, 2013 15:44
Meta Info for Open Graph stuff
<meta property="og:title" content="This is the title of your page" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://yoursite.com/" />
<meta property="og:image" content="http://www.theymc.com/wp-content/themes/theymc/assets/images/ymc_logo_374.png" />
<meta property="fb:admins" content="000000009" />