41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { MongoDB } from "../deps.ts";
|
|
import { DEFAULT_ENV } from "../src/env.ts";
|
|
import { MongoDBExporter } from "../src/exporters/mongodb.ts";
|
|
import { FileStateBackend, Profile } from "../src/state.ts";
|
|
|
|
const env = DEFAULT_ENV;
|
|
const stateBackend = new FileStateBackend("./profile.json");
|
|
const profile = new Profile({ stateBackend, env });
|
|
await profile.readState();
|
|
|
|
if (!profile.state.mongoDbUri) {
|
|
console.error("MongoDB URI not set");
|
|
Deno.exit(1);
|
|
}
|
|
|
|
const mongoDbClient = new MongoDB.MongoClient(profile.state.mongoDbUri);
|
|
const battlesCollection = mongoDbClient.db("splashcat").collection("battles");
|
|
|
|
const filter = {
|
|
"splatNetData.playedTime": {
|
|
$type: "string"
|
|
}
|
|
};
|
|
|
|
const cursor = battlesCollection.find(filter);
|
|
|
|
const oldDocuments = await battlesCollection.countDocuments(filter);
|
|
|
|
console.log(`Found ${oldDocuments} old battles to update...`);
|
|
|
|
for await (const doc of cursor) {
|
|
const { splatNetData, _id } = doc;
|
|
|
|
await battlesCollection.updateOne({ _id }, { "$set": {
|
|
"splatNetData.playedTime": new Date(splatNetData.playedTime),
|
|
}});
|
|
|
|
console.log(`Updated ${splatNetData.playedTime} to ${new Date(splatNetData.playedTime)}`);
|
|
}
|
|
|
|
console.log("Done!") |