1.0.6 • Published 2 years ago

moneasy v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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

# Methods:

- FindOne

  • 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);

# Example:

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"}
});

- UpdateOne

  • 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);

# Example:

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

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago