next/_migrate/ficmas.ts

37 lines
924 B
TypeScript
Raw Normal View History

2023-09-25 19:15:58 -04:00
import { Ficmas } from "../models/challenges/ficmas";
import { MongoClient } from "mongodb";
import mongoose from "mongoose";
import { uri, olduri } from "../lib/dbconfig";
import { Band } from "../models/band";
const cli = new MongoClient(olduri);
export default async function () {
try {
await cli.connect()
await mongoose.connect(uri).then(() => console.log("connect'd"));
const db = cli.db("rockfic_old")
const col = db.collection("ficmas_wishes");
const cursor = col.find({});
for await(const s of cursor) {
const bandList = await Band.find({name: {$in: s.bands}})
const f = new Ficmas({
_id: s.wishid,
bands: bandList.map(a => a._id),
year: s.year,
kink: s.kink,
anniversary: s.isAnniversary,
wisher: s.wisher,
relationship: s.relationship
})
await f.save();
}
} catch(e) {
console.error(e)
} finally {
return 0
}
}