Cosa
Simplified object modeling for MongoDB
Installation
Use your favorite package manager to add cosa to your project.
$ yarn add cosa
Usage
First define a model:
const { Model } = require('cosa');
const UserModel = Model.define({
name: 'UserModel',
collection: 'users',
properties: {
name: { type: 'string', required: true },
email: { type: 'string', required: true, email: true }
}
})
Use the model to add users to the database:
const newUser = UserModel.create({
name: 'John Smith',
email: 'jsmith@example.com'
})
newUser.save()
Fetch all the users in the database:
UserModel
.find({}, { array: true })
.then((users) => {
})
Reference