s3si.ts/scripts/fix-stored-dates.ts

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-03-04 19:19:22 -05:00
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) {
2023-03-07 10:09:32 -05:00
console.error("MongoDB URI not set");
Deno.exit(1);
2023-03-04 19:19:22 -05:00
}
const mongoDbClient = new MongoDB.MongoClient(profile.state.mongoDbUri);
const battlesCollection = mongoDbClient.db("splashcat").collection("battles");
const filter = {
2023-03-07 10:09:32 -05:00
"splatNetData.playedTime": {
$type: "string",
},
2023-03-04 19:19:22 -05:00
};
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) {
2023-03-07 10:09:32 -05:00
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,
)}`,
);
2023-03-04 19:19:22 -05:00
}
2023-03-07 10:09:32 -05:00
console.log("Done!");