webfast 0.1.80 → 0.1.83

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ const { MongoClient } = require('mongodb');
2
+
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
+ }
48
+ }
49
+
50
+ // Execute the main function
51
+ return await main().catch(console.error);
52
+ };
@@ -36,7 +36,19 @@ module.exports = async function(db,collection,query,one = false,array) {
36
36
  const collection = await database.collection(collectionName);
37
37
 
38
38
  // Perform the find query
39
- result = await collection.find(query).toArray();
39
+ if (array.sort != undefined && array.skip != undefined && array.limit != undefined) {
40
+ result = await collection.find(query).sort(array.sort).skip(array.skip).limit(array.limit).toArray();
41
+ } else if (array.limit != undefined && array.sort) {
42
+ result = await collection.find(query).sort(array.sort).limit(array.limit).toArray();
43
+ } else if (array.sort != undefined && array.skip != undefined) {
44
+ result = await collection.find(query).sort(array.sort).skip(array.skip).toArray();
45
+ } else if (array.sort != undefined) {
46
+ result = await collection.find(query).sort(array.sort).toArray();
47
+ } else if (array.limit != undefined) {
48
+ result = await collection.find(query).limit(array.limit).toArray();
49
+ } else {
50
+ result = await collection.find(query).toArray();
51
+ }
40
52
 
41
53
  if (one == true) {
42
54
  result = result[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.80",
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": {