coreio-mongodb

MongoDB integration for CoreIO

Usage no npm install needed!

<script type="module">
  import coreioMongodb from 'https://cdn.skypack.dev/coreio-mongodb';
</script>

README

coreio-mongodb

Build Status

MongoDB integration for CoreIO

Install via npm

$ npm install coreio-mongodb
import CoreIO from 'coreio';
import MongoDBService from 'coreio-mongodb';

// set db conf
CoreIO.setConf('service.mongodb', {
  url: 'mongodb://localhost:27017',
  dbName: 'coreio-test'
});

const TodoModel = CoreIO.createModel('todo', {
  schema: {
    title: { type: 'string', min: 5, max: 100, required: true },
    content: { type: 'string', min: 0, max: 5000 },
    state: { type: 'number', default: 1 }
  },
  service: MongoDBService
});

export default TodoModel;

Import the model in your app, store data and save the model into a MongoDB

import TodoModel from '../path/to/model';

const model = new TodoModel();
model.set({
  title: 'Test model',
  content: 'This is a test content'
});

model.save().then((res) => {
  console.log('Item inserted with id', res.id);
});