Skip to content

Commit 963efdc

Browse files
authored
Update generalFunction.js
add missing bracket
1 parent 27f1b23 commit 963efdc

File tree

1 file changed

+42
-47
lines changed

1 file changed

+42
-47
lines changed
Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
1-
exports = async function(arg){
2-
// This default function will get a value and find a document in MongoDB
3-
// To see plenty more examples of what you can do with functions see:
4-
// https://www.mongodb.com/docs/atlas/app-services/functions/
5-
6-
7-
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab)
8-
var serviceName = "mongodb-atlas";
9-
10-
11-
// Update these to reflect your db/collection
12-
var dbName = "db_name";
13-
var collName = "coll_name";
14-
15-
16-
// Get a collection from the context
17-
var collection = context.services.get(serviceName).db(dbName).collection(collName);
18-
19-
20-
var findResult;
21-
try {
22-
// Get a value from the context (see "Values" tab)
23-
// Update this to reflect your value's name.
24-
var valueName = "value_name";
25-
var value = context.values.get(valueName);
26-
27-
28-
// Execute a FindOne in MongoDB
29-
findResult = await collection.findOne(
30-
{ owner_id: context.user.id, "fieldName": value, "argField": arg},
31-
);
32-
33-
34-
} catch(err) {
35-
console.log("Error occurred while executing findOne:", err.message);
36-
37-
38-
return { error: err.message };
39-
}
40-
41-
42-
// To call other named functions:
43-
// var result = context.functions.execute("function_name", arg1, arg2);
44-
45-
46-
return { result: findResult };
47-
1+
exports = async function (arg) {
2+
// This default function will get a value and find a document in MongoDB
3+
// To see plenty more examples of what you can do with functions see:
4+
// https://www.mongodb.com/docs/atlas/app-services/functions/
5+
6+
// Find the name of the MongoDB service you want to use (see "Linked Data Sources" tab)
7+
var serviceName = "mongodb-atlas";
8+
9+
// Update these to reflect your db/collection
10+
var dbName = "db_name";
11+
var collName = "coll_name";
12+
13+
// Get a collection from the context
14+
var collection = context.services
15+
.get(serviceName)
16+
.db(dbName)
17+
.collection(collName);
18+
19+
var findResult;
20+
try {
21+
// Get a value from the context (see "Values" tab)
22+
// Update this to reflect your value's name.
23+
var valueName = "value_name";
24+
var value = context.values.get(valueName);
25+
26+
// Execute a FindOne in MongoDB
27+
findResult = await collection.findOne({
28+
owner_id: context.user.id,
29+
fieldName: value,
30+
argField: arg,
31+
});
32+
} catch (err) {
33+
console.log("Error occurred while executing findOne:", err.message);
34+
35+
return { error: err.message };
36+
}
37+
38+
// To call other named functions:
39+
// var result = context.functions.execute("function_name", arg1, arg2);
40+
41+
return { result: findResult };
42+
};

0 commit comments

Comments
 (0)