@joystick.js/node-canary 0.0.0-canary.352 → 0.0.0-canary.353
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,24 +4,15 @@ const connect_mongodb = async () => {
|
|
|
4
4
|
const client = await MongoClient.connect("mongodb://localhost:27017");
|
|
5
5
|
const db = client.db("push");
|
|
6
6
|
await db.collection("logs").drop();
|
|
7
|
-
await db.collection("metrics").drop();
|
|
8
7
|
const existing_collections = (await db.listCollections().toArray())?.map((collection) => collection?.name);
|
|
9
8
|
const has_logs_collection = existing_collections?.includes("logs");
|
|
10
|
-
const has_metrics_collection = existing_collections?.includes("metrics");
|
|
11
9
|
if (!has_logs_collection) {
|
|
12
10
|
await db.createCollection("logs", { capped: true, size: MEGABYTE * 50, max: 1e3 });
|
|
13
11
|
}
|
|
14
|
-
if (!has_metrics_collection) {
|
|
15
|
-
await db.createCollection("metrics", { capped: true, size: MEGABYTE * 50, max: 1e3 });
|
|
16
|
-
}
|
|
17
12
|
const logs_index = (await db.collection("logs").listIndexes().toArray())?.find((index) => index?.name === "timestamp_1");
|
|
18
|
-
const metrics_index = (await db.collection("metrics").listIndexes().toArray())?.find((index) => index?.name === "timestamp_1");
|
|
19
13
|
if (!logs_index) {
|
|
20
14
|
await db.collection("logs").createIndex({ timestamp: 1 });
|
|
21
15
|
}
|
|
22
|
-
if (!metrics_index) {
|
|
23
|
-
await db.collection("metrics").createIndex({ timestamp: 1 });
|
|
24
|
-
}
|
|
25
16
|
return db;
|
|
26
17
|
};
|
|
27
18
|
var connectMongoDB_default = connect_mongodb;
|