1.0.8 • Published 4 years ago
mongoengine v1.0.8
Work In Progress - Do Not Install
What is Mongoengine???
An extremely simple mongodb JS engine that aims to provide the following:
- Easy and convenient way to map collections to JS Classes
import { Collection } from "mongoengine"; import { Stringfield, Datefield, Objectfield, Identifier } from "mongoengine";
class Customer extends Collection {
readonly name CollectionName = "customer"; //use this as collection name in the db
_id = Identifier(); //pass in a () => {} to generate custom id's or leave blank for server side generated _ids
name = Stringfield("name", {default: 'Guest'})
email = Stringfield("email", {required: true, unique: true})
phone = Stringfield("phone_number") //leave out optional options
}
let customer = new Customer()
customer.name("Raymond"); //set customer name to Raymond
customer.email("nospam@example.com");
customer.phone("+1-563-489238");
customer.commit(); //save customer to db
```
Inuitive MongoDB Query Syntax
let email = "nospam@example.com"; let limit = 10; cust = Customer.$eq("email", email).fetch(limit);
//Now customer has an ID
let id = customer._id()
const customerName = customer.name(); //read the customer name
```
- Automatic Connection Pooling and Context Management. Simply set environmental variables and write your custom code logic
export MONGO_URL="https://live-ddml-atlas.mongodb.com" export MONGO_HOST="mongo.example.com" export MONGO_DATABASE="testdb" export MONGO_PORT=37027 export MONGO_USER="ironman" export MONGO_PASSWORD="********" export MONGO_POOL=15