0.0.14 • Published 2 years ago

classy-mongo v0.0.14

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

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;
};
0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.3

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago