preformance-mongo

0.0.4 • Public • Published

preformance-mongo

an easy to use and high performance wrapper for mongoose

Changes

+ (v0.0.3) added "skip" option for <mode>.find
+ (v0.0.3) Fixed "find" limit option stuck at 1
+ (v0.0.2) added "autoSave" option for <mode>.save & <mode>.update
+ (v0.0.2) added save function for the model, <mode>.save
+ (v0.0.2) added pure mongoose model for more control over database by <model>.model()
+ (v0.0.2) Fixed some bugs (find limit bug & and errors showing table instead of model)
+ (v0.0.1) Added the main package

Examples

Setup

const pmongo = require("preformance-mongo");
const db = new pmongo.Connection("mongodbURL");
const users = new db.model(
  "users",
  {
    name: String,
    id: String,
    age: Number,
  },
  { index: ["id", "name"] }
);

Uses

create

await users
  .create({
    name: "Sekai",
    id: "15",
    age: 7,
  })
  .then((user) => {
    console.log(user);
  });

find

await users.find({ id: "15" }, { select: { id: 1, name: 1 }, limit: 1 });
//note : limt : 0 = all data that matches the query
//note no limit option will return the same result as limit : 0

save

  await users.save({ id : "15" }}, (user) => {
    user.name = "Sekai966";
  }, {autoSave: true}).then(newUser => {
    console.log(newUser);
  });
  //note that save function won't overwrite the existing user it will give you an error instead
  //disable autoSave option if you want a specific way of saving you can do instead something like that in pure mongoose|
  await users.save({ id : "15" }}, (user) => {
    user.name = "Sekai966";
    users.model().update({name : "Sekai966"}, {father : "Sekai's Father"});
    //or
    user.save();
  }, {autoSave: false}).then(newUser => {
    console.log(newUser);
  });

update

  await users.update({ id : "15" }}, (user) => {
    user.name = "Sekai966";
  }, {autoSave: true}).then(newUser => {
    console.log(newUser);
  });

database info & functions

const pmongo = require("preformance-mongo");
const db = new pmongo.Connection("mongodbURL");

version

pmongo.version;

destroyDatabase

db.destroyDatabase();

getUptime

db.getUptime();

stats

db.stats();

Package Sidebar

Install

npm i preformance-mongo

Weekly Downloads

31

Version

0.0.4

License

ISC

Unpacked Size

8.78 kB

Total Files

5

Last publish

Collaborators

  • sekai966