Socket
Socket
Sign inDemoInstall

classy-mongo

Package Overview
Dependencies
159
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    classy-mongo

typed odm for mongodb


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Classy Mongo

const classy = require("classy-mongo");

classy.connect("mongodb://localhost:27017/my-database").then(() => {
  console.log("Connected to DB!");
});
const { Model } = require("classy-mongo");

class Book extends Model {
  name = String.prototype;
  pages = [String.prototype];
  isSpecial = Boolean.prototype;

  get pageCount() {
    return this.pages.length;
  }

  static getSpecials() {
    return this.find({ isSpecial: true });
  }
}

module.exports = Book;
const Book = require("../models/Book");

module.exports = async () => {
  const result = await Book.insertOne({
    name: "Harry Potter",
    pages: ["....", "....", "....", "...."],
  });

  const book = await Book.findById(result.insertedId);

  console.log(book.pageCount); // 4

  return book;
};

FAQs

Last updated on 06 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc