webfast 0.1.82 → 0.1.83

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,52 +1,52 @@
1
1
  const { MongoClient } = require('mongodb');
2
- module.exports = async function(program,db,collection,query,callback) {
3
- // Ensure the MongoDB connection string is provided
4
- // Ensure the MongoDB connection string is provided
5
- if (!process.env.mongo) {
6
- console.error('MongoDB connection string not provided. Set process.env.mongo.');
7
- process.exit(1);
8
- }
9
-
10
- // Define the MongoDB URI
11
- const uri = process.env.mongo;
12
-
13
- // Define the database and collection name
14
- const dbName = db;
15
- const collectionName = collection;
16
-
17
- async function main() {
18
- // Create a new MongoClient
19
- const client = new MongoClient(uri);
20
-
21
- try {
22
- // Connect to the MongoDB server
23
- await client.connect();
24
- console.log('Connected to the MongoDB server');
25
2
 
26
- // Select the database
27
- const database = client.db(dbName);
28
-
29
- // Select the collection
30
- const collection = database.collection(collectionName);
31
-
32
- // Perform the find query
33
- let result = await collection.find(query).toArray();
34
-
35
- if (one) {
36
- result = result[0];
37
- }
38
-
39
- // Process the result
40
- console.log('Query result:', result);
41
- } catch (error) {
42
- console.error('Error executing MongoDB query:', error);
43
- } finally {
44
- // Close the MongoDB connection
45
- await client.close();
46
- }
3
+ module.exports = async function (program, db, collection, pipeline, one = false) {
4
+ // Ensure the MongoDB connection string is provided
5
+ if (!process.env.mongo) {
6
+ console.error('MongoDB connection string not provided. Set process.env.mongo.');
7
+ process.exit(1);
8
+ }
9
+
10
+ // Define the MongoDB URI
11
+ const uri = process.env.mongo;
12
+
13
+ // Define the database and collection name
14
+ const dbName = db;
15
+ const collectionName = collection;
16
+
17
+ async function main() {
18
+ // Create a new MongoClient
19
+ const client = new MongoClient(uri);
20
+
21
+ try {
22
+ // Connect to the MongoDB server
23
+ await client.connect();
24
+ console.log('Connected to the MongoDB server');
25
+
26
+ // Select the database
27
+ const database = client.db(dbName);
28
+
29
+ // Select the collection
30
+ const collection = database.collection(collectionName);
31
+
32
+ // Perform the aggregation query
33
+ let result = await collection.aggregate(pipeline).toArray();
34
+
35
+ if (one) {
36
+ result = result[0];
37
+ }
38
+
39
+ // Process the result
40
+ console.log('Aggregation result:', result);
41
+ return result;
42
+ } catch (error) {
43
+ console.error('Error executing MongoDB aggregation:', error);
44
+ } finally {
45
+ // Close the MongoDB connection
46
+ await client.close();
47
47
  }
48
+ }
48
49
 
49
- // Execute the main function
50
- return await main().catch(console.error);
51
-
52
- }
50
+ // Execute the main function
51
+ return await main().catch(console.error);
52
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.82",
3
+ "version": "0.1.83",
4
4
  "description": "WebFast! Bot Application, including TON mini-apps for makign it easy and fast to build ini-apps",
5
5
  "main": "index.js",
6
6
  "repository": {