It's a repository to simplify the mongoose Lib.
Use npm/yarn i/add simple-mongooserepo
https://github.com/rafaelhueb92/MongooseRepo
Have NodeJs Installed
Include your Mongo URL on the constructor like this:
const mongooose = require("simple-mongooserepo")(<your Mongo URL>);
This lib is singleton, so if you need to call the lib in other part of the projetct just do that:
const mongooose = require("simple-mongooserepo")();
To Create a Model just define an Schema:
const definitions = { name:String, age:Number }
const schemaOptions = { timeStamps:true }
const personRepo = await mongoose.createModel("person", definitions,schemaOptions)
If you Want Create a Repository just call repository file and extends into a class passing the Model:
const Person = mongoose.createRepository("person", definition, options); const Repository = require("simple-mongooserepo/lib/repository");
class PersonRepo extends Repository{ constructor(){ super(Person) } }
Theres is a utils file that has funtions to help to use the lib,
to use then, just code like bellow:
const utils = require("simple-mongooserepo/lib/utils")
To compare the encryption just use the function comparePassword().
A type of schema used to location, you cant destruct it using atribute type from lib.
A type of schema used to encrypt.
To insert value in this type:
{ ... password: {value:"123"} ... }
The same to retrieve:
const { value } = response.password;