next/_migrate/bands.ts

33 lines
752 B
TypeScript
Raw Normal View History

2023-09-25 19:15:58 -04:00
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 {
console.debug(olduri)
await cli.connect()
await mongoose.connect(uri).then(() => console.log("connect'd"));
const db = cli.db("rockfic_old")
const col = db.collection("bands");
const cursor = col.find({});
for await(const s of cursor) {
// console.debug(s.name)
const nb = new Band({
_id: s._id,
name: s.name,
locked: s.locked,
characters: s.characters
})
await nb.save()
}
} catch(e) {
console.error(e)
} finally {
return 0
}
}