This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.reviews.aggregate([ | |
{ | |
$group: { | |
_id: "$bookId", | |
averageRating: { | |
$avg: "$rating" | |
} | |
} | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
$match: { | |
rated: "TV-PG", | |
}, | |
}, | |
{ | |
$match: | |
/** | |
* query: The query in MQL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENDPOINT | |
-------- | |
https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta | |
API KEY | |
-------- | |
0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fyQ(date) { | |
var d = new Date(date); | |
var month = d.getMonth()+1; | |
var year = d.getFullYear(); | |
// FY | |
if (month > 1) { | |
var year = year + 1 | |
} | |
Logger.log("Year: " + year + " month: " + month) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
|* Insert this code into your Google Sheets Script Editor | |
|* From there, you can insert into a cell in the sheet =fetchCode("somevalue") | |
|* This will return the value fetched from the database and set a last date fetched. | |
|* Next time you want to fetch - it will compare the last date fetched. If it's more than a day | |
|* It will fetch again - otherwise, not. | |
**/ | |
function fetchCode(code) { | |
if (!code || code == "") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports = function(phoneNumber){ | |
const host = "lookups.twilio.com"; | |
const path = `/v1/PhoneNumbers/${phoneNumber}`; | |
const lookupUrl = `https://lookups.twilio.com/v1/PhoneNumbers/${phoneNumber}`; | |
const http = context.services.get("http"); | |
const { SID, Secret } = context.values.get("twilioCredentials"); | |
return http.get({ | |
"scheme": "https", | |
host, | |
path, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**** | |
* This function runs automatically and adds a menu item to Google Sheets | |
****/ | |
function onOpen() { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet(); | |
sheet.setActiveSheet(sheet.getSheetByName("Events")); | |
var entries = [{ | |
name : "Export Events to MongoDB", | |
functionName : "exportEventsToMongoDB" | |
},{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**** | |
* Michael Lynn - http://blog.mlynn.org | |
* Stitching Sheets - Integrating Google Sheets with MongoDB Using MongoDB Stitch | |
****/ | |
// Create an object which contains keys for each column in the spreadsheet | |
var columns = { // 0 indexed | |
type: 2, | |
date_start: 3, | |
date_end: 4, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**** | |
* Delete the events from the Calendar and remover the eventID Reference from the sheet - wipeout. | |
****/ | |
function removeEventsFromMongoDB() { | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = spreadsheet.getSheetByName("Events"); | |
var headerRows = 1; // Number of rows of header info (to skip) | |
var range = sheet.getDataRange(); | |
var numRows = range.getNumRows(); | |
var data = range.getValues(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports = async function(payload) { | |
const mongodb = context.services.get("mongodb-atlas"); | |
const eventsdb = mongodb.db("events"); | |
const eventscoll = eventsdb.collection("events"); | |
const result= await eventscoll.insertOne(payload.query); | |
var id = result.insertedId.toString(); | |
if(result) { | |
return JSON.stringify(id,false,false); | |
} | |
return { text: `Error saving` }; |
NewerOlder