Last active
June 15, 2020 11:23
-
-
Save mizchi/40ce2ff2ac4d7d9f2a57f75e42b35fb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dotenv from "dotenv"; | |
import mongoose from "mongoose"; | |
import { prop, getModelForClass } from "@typegoose/typegoose"; | |
dotenv.config(); | |
class Task { | |
@prop({ required: true }) | |
name!: string; | |
@prop({ required: true }) | |
done!: boolean; | |
} | |
const TaskModel = getModelForClass(Task); | |
(async () => { | |
await mongoose.connect(process.env.MONGO_HOST as string, { | |
user: process.env.MONGO_USER as string, | |
pass: process.env.MONGO_PASSWORD as string, | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
}); | |
console.log("connected"); | |
await TaskModel.create({ | |
name: "garbage", | |
done: false, | |
}); | |
const tasks = await TaskModel.find({}); | |
console.log(tasks); | |
process.exit(0); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment