@mongoly/core
TypeScript icon, indicating that this package has built-in type declarations

0.1.11 • Public • Published

@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

Package Sidebar

Install

npm i @mongoly/core

Weekly Downloads

1

Version

0.1.11

License

MIT

Unpacked Size

28.4 kB

Total Files

35

Last publish

Collaborators

  • agent-ly