coreio-mongodb

0.1.3 • Public • Published

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);
});

/coreio-mongodb/

    Package Sidebar

    Install

    npm i coreio-mongodb

    Weekly Downloads

    3

    Version

    0.1.3

    License

    MIT

    Unpacked Size

    17 kB

    Total Files

    5

    Last publish

    Collaborators

    • andifeind
    • kippis
    • firetux