-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'copy-push-files-action-9962554850-upload-functions' int…
…o development
- Loading branch information
Showing
10 changed files
with
503 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
exports = async function(changeEvent){ | ||
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab) | ||
var serviceName = "mongodb-atlas"; | ||
|
||
// Update these to reflect your db/collection | ||
var dbName = "sample_supplies"; | ||
var collName = "sales"; | ||
|
||
// Get a collection from the context | ||
var collection = context.services.get(serviceName).db(dbName).collection(collName); | ||
|
||
const deleteFilter = { "storeLocation": changeEvent.fullDocument.storeLocation }; | ||
|
||
try { | ||
deleteResult = await collection.deleteMany(deleteFilter); | ||
return deleteResult["deletedCount"]; | ||
} catch(err) { | ||
console.log("Failed to delete item: ", err.message); | ||
return { error: err.message }; | ||
} | ||
}; | ||
|
||
// In the Testing Console tab, paste the code below and click Run: | ||
/* | ||
exports({ | ||
_id: {_data: '62548f79e7f11292792497cc' }, | ||
operationType: 'insert', | ||
clusterTime: { | ||
"$timestamp": { | ||
t: 1649712420, | ||
i:6 | ||
} | ||
}, | ||
ns: { | ||
db: 'engineering', | ||
coll: 'users' | ||
}, | ||
documentKey: { | ||
storeLocation: 'East Appleton', | ||
_id: "62548f79e7f11292792497cc" | ||
}, | ||
fullDocument: { | ||
_id: "599af247bb69cd89961c986d", | ||
storeLocation: 'East Appleton', | ||
couponUsed: false | ||
} | ||
}) | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
exports = async function(changeEvent){ | ||
console.log(JSON.stringify(changeEvent)); | ||
|
||
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab) | ||
var serviceName = "mongodb-atlas"; | ||
|
||
// Update these to reflect your db/collection | ||
var dbName = "sample_supplies"; | ||
var collName = "sales"; | ||
|
||
// Get a collection from the context | ||
var collection = context.services.get(serviceName).db(dbName).collection(collName); | ||
|
||
const deleteFilter = { "_id": changeEvent._id._data }; | ||
try { | ||
deleteResult = await collection.deleteOne(deleteFilter); | ||
return deleteResult["deletedCount"]; | ||
} catch(err) { | ||
console.log("Failed to delete item: ", err.message); | ||
return { error: err.message }; | ||
} | ||
}; | ||
|
||
// In the Testing Console tab, paste the code below and click Run: | ||
/* | ||
exports({ | ||
_id: {_data: '62548f79e7f11292792497cc' }, | ||
operationType: 'insert', | ||
clusterTime: { | ||
"$timestamp": { | ||
t: 1649712420, | ||
i:6 | ||
} | ||
}, | ||
ns: { | ||
db: 'engineering', | ||
coll: 'users' | ||
}, | ||
documentKey: { | ||
storeLocation: 'East Appleton', | ||
_id: "62548f79e7f11292792497cc" | ||
}, | ||
fullDocument: { | ||
_id: "599af247bb69cd89961c986d", | ||
storeLocation: 'East Appleton', | ||
couponUsed: false | ||
} | ||
}) | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
exports = async function(changeEvent){ | ||
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab) | ||
var serviceName = "mongodb-atlas"; | ||
|
||
// Update these to reflect your db/collection | ||
var dbName = "sample_supplies"; | ||
var collName = "sales"; | ||
|
||
// Get a collection from the context | ||
var collection = context.services.get(serviceName).db(dbName).collection(collName); | ||
|
||
// To test this example, uncomment the following line: | ||
// await collection.insertOne({"storeLocation":changeEvent.fullDocument.storeLocation, "couponUsed":true}); | ||
|
||
try { | ||
findResults = await collection.find({storeLocation: changeEvent.fullDocument.storeLocation}); | ||
return findResults; | ||
} catch(err) { | ||
console.log("Failed to find item: ", err.message); | ||
return { error: err.message }; | ||
} | ||
} | ||
|
||
// In the Testing Console tab, paste the code below and click Run: | ||
/* | ||
exports({ | ||
_id: {_data: '599af247bb69cd89961c986d' }, | ||
operationType: 'insert', | ||
clusterTime: { | ||
"$timestamp": { | ||
t: 1649712420, | ||
i:6 | ||
} | ||
}, | ||
ns: { | ||
db: 'engineering', | ||
coll: 'users' | ||
}, | ||
documentKey: { | ||
storeLocation: 'East Appleton', | ||
_id: "599af247bb69cd89961c986d" | ||
}, | ||
fullDocument: { | ||
_id: "599af247bb69cd89961c986d", | ||
storeLocation: 'East Appleton', | ||
couponUsed: false | ||
} | ||
}); | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
exports = async function(changeEvent){ | ||
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab) | ||
var serviceName = "mongodb-atlas"; | ||
|
||
// Update these to reflect your db/collection | ||
var dbName = "sample_supplies"; | ||
var collName = "sales"; | ||
|
||
// Get a collection from the context | ||
var collection = context.services.get(serviceName).db(dbName).collection(collName); | ||
|
||
// To test this example, uncomment the following line: | ||
// collection.updateOne({_id:"599af247bb69cd89961c986d", "storeLocation":"East Appleton", "couponUsed":false}, {upsert:true}); | ||
|
||
const query = { "_id": changeEvent._id._data }; | ||
|
||
try { | ||
doc = await collection.findOne(query); | ||
return doc; | ||
|
||
} catch(err) { | ||
console.log("Failed to find item: ", err.message); | ||
return { error: err.message }; | ||
} | ||
}; | ||
|
||
// In the Testing Console tab, paste the code below and click Run: | ||
/* | ||
exports({ | ||
_id: {_data: '599af247bb69cd89961c986d' }, | ||
operationType: 'insert', | ||
clusterTime: { | ||
"$timestamp": { | ||
t: 1649712420, | ||
i:6 | ||
} | ||
}, | ||
ns: { | ||
db: 'engineering', | ||
coll: 'users' | ||
}, | ||
documentKey: { | ||
storeLocation: 'East Appleton', | ||
_id: { | ||
"$oid": "599af247bb69cd89961c986d" | ||
} | ||
}, | ||
fullDocument: { | ||
_id: { | ||
"$oid": "599af247bb69cd89961c986d" | ||
}, | ||
storeLocation: 'East Appleton', | ||
couponUsed: false | ||
} | ||
}); | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
exports = async function (changeEvent) { | ||
var collection = context.services | ||
.get("mongodb-atlas") | ||
.db("sample_supplies") | ||
.collection("sales"); | ||
|
||
try { | ||
var result = await collection.insertMany([ | ||
{"storeLocation":changeEvent.fullDocument.storeLocation, "items":changeEvent.fullDocument.items}, | ||
]); | ||
return result; | ||
} catch (err) { | ||
console.log("Failed to insert items: ", err.message); | ||
return { error: err.message }; | ||
} | ||
} | ||
|
||
// In the Testing Console tab, paste the code below and click Run: | ||
/* | ||
exports({ | ||
_id: {_data: '62548f79e7f11292792497cc' }, | ||
operationType: 'insert', | ||
clusterTime: { | ||
"$timestamp": { | ||
t: 1649712420, | ||
i:6 | ||
} | ||
}, | ||
ns: { | ||
db: 'engineering', | ||
coll: 'users' | ||
}, | ||
documentKey: { | ||
storeLocation: 'East Appleton', | ||
_id: { | ||
"$oid": "62548f79e7f11292792497cc" | ||
} | ||
}, | ||
fullDocument: { | ||
_id: { | ||
"$oid": "599af247bb69cd89961c986d" | ||
}, | ||
storeLocation: 'East Appleton', | ||
items: ["envelopes"] | ||
} | ||
}) | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
exports = async function (changeEvent) { | ||
|
||
console.log(JSON.stringify(changeEvent)); | ||
|
||
var collection = context.services | ||
.get("mongodb-atlas") | ||
.db("sample_supplies") | ||
.collection("sales"); | ||
|
||
try { | ||
var result = await collection.insertOne({"storeLocation":changeEvent.fullDocument.storeLocation, | ||
"items":changeEvent.fullDocument.items}); | ||
return result; | ||
} catch (err) { | ||
console.log("Failed to insert item: ", err.message); | ||
return { error: err.message }; | ||
} | ||
} | ||
|
||
// In the Testing Console tab, paste the code below and click Run: | ||
/* | ||
exports({ | ||
_id: {_data: '62548f79e7f11292792497cc' }, | ||
operationType: 'insert', | ||
clusterTime: { | ||
"$timestamp": { | ||
t: 1649712420, | ||
i:6 | ||
} | ||
}, | ||
ns: { | ||
db: 'engineering', | ||
coll: 'users' | ||
}, | ||
documentKey: { | ||
storeLocation: 'East Appleton', | ||
_id: "62548f79e7f11292792497cc" | ||
}, | ||
fullDocument: { | ||
_id: "599af247bb69cd89961c986d", | ||
storeLocation: 'East Appleton', | ||
items: ["envelopes"] | ||
} | ||
}) | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
exports = async function(changeEvent){ | ||
var serviceName = "mongodb-atlas"; | ||
var dbName = "sample_supplies"; | ||
var collName = "sales"; | ||
|
||
var collection = context.services.get(serviceName).db(dbName).collection(collName); | ||
const query = { "_id": changeEvent.documentKey._id }; | ||
|
||
const projection = { | ||
_id:0, | ||
storeLocation:1, | ||
items: 1 | ||
} | ||
|
||
try { | ||
doc = await collection.findOne(query, projection); | ||
return doc; | ||
} catch(err) { | ||
console.log("Failed to find item: ", err.message); | ||
return { error: err.message }; | ||
} | ||
}; | ||
|
||
// In the Testing Console tab, paste the code below and click Run: | ||
/* | ||
exports({ | ||
_id: {_data: '62548f79e7f11292792497cc' }, | ||
operationType: 'insert', | ||
clusterTime: { | ||
"$timestamp": { | ||
t: 1649712420, | ||
i:6 | ||
} | ||
}, | ||
ns: { | ||
db: 'engineering', | ||
coll: 'users' | ||
}, | ||
documentKey: { | ||
storeLocation: 'East Appleton', | ||
_id: '62548f79e7f11292792497cc' | ||
}, | ||
fullDocument: { | ||
_id: "599af247bb69cd89961c986d", | ||
storeLocation: 'East Appleton', | ||
items: ["envelopes"] | ||
} | ||
}) | ||
*/ |
Oops, something went wrong.