0.0.14 • Published 10 months ago
mongo-database-handler v0.0.14
mongo-database-handler
A simple MongoDB database handler for NodeJS. This package works with various uses, e.g. discord.js, express.js, etc. Assuming you may already know how to use MongoDB and Mongoose.
Usage
To initiate the database handler, put this code inside your code.
Typescript:
import { DatabaseHandler } from "mongo-database-handler";
import path from "path";
// Put your Models' directory inside the init() function.
// Remember to put this inside an async function for the await to work.
await new DatabaseHandler().init(path.join(__dirname, "models"));
Javascript/NodeJS:
const { DatabaseHandler } = require("mongo-database-handler");
const path = require("path");
// Put your Models' directory inside the init() function.
// Remember to put this inside an async function for the await to work.
await new DatabaseHandler().init(path.join(__dirname, "models"));
To create a model, simply look at this example.
Typescript:
import { Model } from "mongo-database-handler";
// Replace Model with whatever name you like for the model.
class Model extends Template {
constructor() {
super(
{
name: {
type: String,
},
value: {
type: String,
},
},
"name"
);
}
}