moneasy

1.0.6 • Public • Published

moneasy

With moneasy, using the mongoose npm module will be made easy

Installation

Execute this command in your project's cmd:

npm i moneasy

# Tags

  • TypeDefs:
    • MongooseModel Model | Your mongoose model from which you want to retrieve data
    • Object DocumentToFind | The document to retrieve
    • Boolean CreateIfDoesntExist (optional | default: false) | If true, a new model will be created with the value specified in the previous parameter
    • String ValueToFind (optional | default: "") | The specific value to retrieve within the document
const mon = require("moneasy");

await mon.FindOne(Model, DocumentToFind, CreateIfDoesntExist, ValueToFind);
const mon = require("moneasy");
const Users = require("./databases/models/Users.js");

/*
Users database:
  - userId: 01
  - userName: Kevin
*/

mon.FindOne(Users, {userId: "01"}, true, "userName").then((res) => {
  console.log(res); // Returns: "Kevin"
});

mon.FindOne(Users, {userId: "02", userName: "Joe"}, true, "userName").then((res) => {
  console.log(res); // Returns: "Joe"
});

mon.FindOne(Users, {userId: "02"}, false).then((res) => {
  console.log(res); // Returns: {userId: 02, userName: "Joe"}
});

  • TypeDefs:
    • MongooseModel Model | The mongoose model you want to update
    • Object DocumentToFind | The document to find
    • Object DocumentToUpdate | The document you want to update (usually, this one has the same value as DocumentToFind)
    • Object ValueToUpdate | The new value of the document
    • Object ValueToCreate | The new value to create if the document is not found
const mon = require("moneasy");

await mon.UpdateOne(Model, DocumentToFind, DocumentToUpdate, ValueToUpdate, ValueToCreate);
const mon = require("moneasy");

mon.UpdateOne(Users, {userId: "01"}, {userId: "01"}, {userName: "Tom"}, {userId: "01", userName: "Tom"}).then((res) => {
  console.log(res); // Returns: {userId: "01", userName: "Tom"}
});

mon.UpdateOne(Users, {userId: "02"}, {userId: "02"}, {userName: "Alexa"}, {userId: "02", userName: "Alexa"}).then((res) => {
  console.log(res); // Returns: {userId: "02", userName: "Alexa"}
});

This package will be continuously updated, adding even more options to make your development with mongoose easier

License

ISC License

ISC

Package Sidebar

Install

npm i moneasy

Weekly Downloads

2

Version

1.0.6

License

ISC

Unpacked Size

6.11 kB

Total Files

5

Last publish

Collaborators

  • kiwisitoop