@mongoly/core
v0.1.11
Published
A lightweight MongoDB utility/wrapper library for Node.js
Downloads
3
Maintainers
Readme
@mongoly/core
The core of mongoly. This library includes all the primary functionality and goals of this project.
Installation
npm install mongodb @mongoly/core
Usage
import { MongoClient } from 'mongodb';
import { ensureJSONSchema, ensureIndexes } from '@mongoly/core';
async function bootstrap() {
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();
const db = client.db('test');
await ensureJSONSchema(db, 'users', {
bsonType: 'object'
properties: {
name: { bsonType: 'string' },
age: { bsonType: 'number'},
},
required: ['name', 'age']
});
const collection = db.collection('users');
await ensureIndexes(collection, [
{
key: { name: 1 },
unique: true,
}
]);
await collection.insertOne({ name: 'John', age: 27 })
await collection.insertOne({ name: 'Jane', age: '27' }) // Document Validation Error
}
Whats left?
If you have anything else in mind just let me know, but remember the library is meant to be a lightweight utility/wrapper for MongoDB.
- Create a transformer for JSON schema document validation errors to make displaying them easier.
Ecosystem
@mongoly/nestjs
: A NestJS wrapper for mongoly.