Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active June 15, 2020 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/40ce2ff2ac4d7d9f2a57f75e42b35fb2 to your computer and use it in GitHub Desktop.
Save mizchi/40ce2ff2ac4d7d9f2a57f75e42b35fb2 to your computer and use it in GitHub Desktop.
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