Skip to content

Commit 4e0fd17

Browse files
committed
Merge branch 'copy-push-files-action-9962554850-upload-functions' into development
2 parents bbbe1e0 + 0d9fc40 commit 4e0fd17

File tree

10 files changed

+503
-0
lines changed

10 files changed

+503
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
exports = async function(changeEvent){
2+
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab)
3+
var serviceName = "mongodb-atlas";
4+
5+
// Update these to reflect your db/collection
6+
var dbName = "sample_supplies";
7+
var collName = "sales";
8+
9+
// Get a collection from the context
10+
var collection = context.services.get(serviceName).db(dbName).collection(collName);
11+
12+
const deleteFilter = { "storeLocation": changeEvent.fullDocument.storeLocation };
13+
14+
try {
15+
deleteResult = await collection.deleteMany(deleteFilter);
16+
return deleteResult["deletedCount"];
17+
} catch(err) {
18+
console.log("Failed to delete item: ", err.message);
19+
return { error: err.message };
20+
}
21+
};
22+
23+
// In the Testing Console tab, paste the code below and click Run:
24+
/*
25+
exports({
26+
_id: {_data: '62548f79e7f11292792497cc' },
27+
operationType: 'insert',
28+
clusterTime: {
29+
"$timestamp": {
30+
t: 1649712420,
31+
i:6
32+
}
33+
},
34+
ns: {
35+
db: 'engineering',
36+
coll: 'users'
37+
},
38+
documentKey: {
39+
storeLocation: 'East Appleton',
40+
_id: "62548f79e7f11292792497cc"
41+
},
42+
fullDocument: {
43+
_id: "599af247bb69cd89961c986d",
44+
storeLocation: 'East Appleton',
45+
couponUsed: false
46+
}
47+
})
48+
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
exports = async function(changeEvent){
2+
console.log(JSON.stringify(changeEvent));
3+
4+
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab)
5+
var serviceName = "mongodb-atlas";
6+
7+
// Update these to reflect your db/collection
8+
var dbName = "sample_supplies";
9+
var collName = "sales";
10+
11+
// Get a collection from the context
12+
var collection = context.services.get(serviceName).db(dbName).collection(collName);
13+
14+
const deleteFilter = { "_id": changeEvent._id._data };
15+
try {
16+
deleteResult = await collection.deleteOne(deleteFilter);
17+
return deleteResult["deletedCount"];
18+
} catch(err) {
19+
console.log("Failed to delete item: ", err.message);
20+
return { error: err.message };
21+
}
22+
};
23+
24+
// In the Testing Console tab, paste the code below and click Run:
25+
/*
26+
exports({
27+
_id: {_data: '62548f79e7f11292792497cc' },
28+
operationType: 'insert',
29+
clusterTime: {
30+
"$timestamp": {
31+
t: 1649712420,
32+
i:6
33+
}
34+
},
35+
ns: {
36+
db: 'engineering',
37+
coll: 'users'
38+
},
39+
documentKey: {
40+
storeLocation: 'East Appleton',
41+
_id: "62548f79e7f11292792497cc"
42+
},
43+
fullDocument: {
44+
_id: "599af247bb69cd89961c986d",
45+
storeLocation: 'East Appleton',
46+
couponUsed: false
47+
}
48+
})
49+
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
exports = async function(changeEvent){
2+
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab)
3+
var serviceName = "mongodb-atlas";
4+
5+
// Update these to reflect your db/collection
6+
var dbName = "sample_supplies";
7+
var collName = "sales";
8+
9+
// Get a collection from the context
10+
var collection = context.services.get(serviceName).db(dbName).collection(collName);
11+
12+
// To test this example, uncomment the following line:
13+
// await collection.insertOne({"storeLocation":changeEvent.fullDocument.storeLocation, "couponUsed":true});
14+
15+
try {
16+
findResults = await collection.find({storeLocation: changeEvent.fullDocument.storeLocation});
17+
return findResults;
18+
} catch(err) {
19+
console.log("Failed to find item: ", err.message);
20+
return { error: err.message };
21+
}
22+
}
23+
24+
// In the Testing Console tab, paste the code below and click Run:
25+
/*
26+
exports({
27+
_id: {_data: '599af247bb69cd89961c986d' },
28+
operationType: 'insert',
29+
clusterTime: {
30+
"$timestamp": {
31+
t: 1649712420,
32+
i:6
33+
}
34+
},
35+
ns: {
36+
db: 'engineering',
37+
coll: 'users'
38+
},
39+
documentKey: {
40+
storeLocation: 'East Appleton',
41+
_id: "599af247bb69cd89961c986d"
42+
},
43+
fullDocument: {
44+
_id: "599af247bb69cd89961c986d",
45+
storeLocation: 'East Appleton',
46+
couponUsed: false
47+
}
48+
});
49+
*/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
exports = async function(changeEvent){
2+
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab)
3+
var serviceName = "mongodb-atlas";
4+
5+
// Update these to reflect your db/collection
6+
var dbName = "sample_supplies";
7+
var collName = "sales";
8+
9+
// Get a collection from the context
10+
var collection = context.services.get(serviceName).db(dbName).collection(collName);
11+
12+
// To test this example, uncomment the following line:
13+
// collection.updateOne({_id:"599af247bb69cd89961c986d", "storeLocation":"East Appleton", "couponUsed":false}, {upsert:true});
14+
15+
const query = { "_id": changeEvent._id._data };
16+
17+
try {
18+
doc = await collection.findOne(query);
19+
return doc;
20+
21+
} catch(err) {
22+
console.log("Failed to find item: ", err.message);
23+
return { error: err.message };
24+
}
25+
};
26+
27+
// In the Testing Console tab, paste the code below and click Run:
28+
/*
29+
exports({
30+
_id: {_data: '599af247bb69cd89961c986d' },
31+
operationType: 'insert',
32+
clusterTime: {
33+
"$timestamp": {
34+
t: 1649712420,
35+
i:6
36+
}
37+
},
38+
ns: {
39+
db: 'engineering',
40+
coll: 'users'
41+
},
42+
documentKey: {
43+
storeLocation: 'East Appleton',
44+
_id: {
45+
"$oid": "599af247bb69cd89961c986d"
46+
}
47+
},
48+
fullDocument: {
49+
_id: {
50+
"$oid": "599af247bb69cd89961c986d"
51+
},
52+
storeLocation: 'East Appleton',
53+
couponUsed: false
54+
}
55+
});
56+
*/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
exports = async function (changeEvent) {
2+
var collection = context.services
3+
.get("mongodb-atlas")
4+
.db("sample_supplies")
5+
.collection("sales");
6+
7+
try {
8+
var result = await collection.insertMany([
9+
{"storeLocation":changeEvent.fullDocument.storeLocation, "items":changeEvent.fullDocument.items},
10+
]);
11+
return result;
12+
} catch (err) {
13+
console.log("Failed to insert items: ", err.message);
14+
return { error: err.message };
15+
}
16+
}
17+
18+
// In the Testing Console tab, paste the code below and click Run:
19+
/*
20+
exports({
21+
_id: {_data: '62548f79e7f11292792497cc' },
22+
operationType: 'insert',
23+
clusterTime: {
24+
"$timestamp": {
25+
t: 1649712420,
26+
i:6
27+
}
28+
},
29+
ns: {
30+
db: 'engineering',
31+
coll: 'users'
32+
},
33+
documentKey: {
34+
storeLocation: 'East Appleton',
35+
_id: {
36+
"$oid": "62548f79e7f11292792497cc"
37+
}
38+
},
39+
fullDocument: {
40+
_id: {
41+
"$oid": "599af247bb69cd89961c986d"
42+
},
43+
storeLocation: 'East Appleton',
44+
items: ["envelopes"]
45+
}
46+
})
47+
*/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
exports = async function (changeEvent) {
2+
3+
console.log(JSON.stringify(changeEvent));
4+
5+
var collection = context.services
6+
.get("mongodb-atlas")
7+
.db("sample_supplies")
8+
.collection("sales");
9+
10+
try {
11+
var result = await collection.insertOne({"storeLocation":changeEvent.fullDocument.storeLocation,
12+
"items":changeEvent.fullDocument.items});
13+
return result;
14+
} catch (err) {
15+
console.log("Failed to insert item: ", err.message);
16+
return { error: err.message };
17+
}
18+
}
19+
20+
// In the Testing Console tab, paste the code below and click Run:
21+
/*
22+
exports({
23+
_id: {_data: '62548f79e7f11292792497cc' },
24+
operationType: 'insert',
25+
clusterTime: {
26+
"$timestamp": {
27+
t: 1649712420,
28+
i:6
29+
}
30+
},
31+
ns: {
32+
db: 'engineering',
33+
coll: 'users'
34+
},
35+
documentKey: {
36+
storeLocation: 'East Appleton',
37+
_id: "62548f79e7f11292792497cc"
38+
},
39+
fullDocument: {
40+
_id: "599af247bb69cd89961c986d",
41+
storeLocation: 'East Appleton',
42+
items: ["envelopes"]
43+
}
44+
})
45+
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
exports = async function(changeEvent){
2+
var serviceName = "mongodb-atlas";
3+
var dbName = "sample_supplies";
4+
var collName = "sales";
5+
6+
var collection = context.services.get(serviceName).db(dbName).collection(collName);
7+
const query = { "_id": changeEvent.documentKey._id };
8+
9+
const projection = {
10+
_id:0,
11+
storeLocation:1,
12+
items: 1
13+
}
14+
15+
try {
16+
doc = await collection.findOne(query, projection);
17+
return doc;
18+
} catch(err) {
19+
console.log("Failed to find item: ", err.message);
20+
return { error: err.message };
21+
}
22+
};
23+
24+
// In the Testing Console tab, paste the code below and click Run:
25+
/*
26+
exports({
27+
_id: {_data: '62548f79e7f11292792497cc' },
28+
operationType: 'insert',
29+
clusterTime: {
30+
"$timestamp": {
31+
t: 1649712420,
32+
i:6
33+
}
34+
},
35+
ns: {
36+
db: 'engineering',
37+
coll: 'users'
38+
},
39+
documentKey: {
40+
storeLocation: 'East Appleton',
41+
_id: '62548f79e7f11292792497cc'
42+
},
43+
fullDocument: {
44+
_id: "599af247bb69cd89961c986d",
45+
storeLocation: 'East Appleton',
46+
items: ["envelopes"]
47+
}
48+
})
49+
*/

0 commit comments

Comments
 (0)