js-data-mongodb 1.0.0-alpha.3

js-data logo

js-data-mongodb

Slack Status npm version Circle CI npm downloads Coverage Status Codacy

MongoDB adapter for js-data.

Table of contents

Quick Start

npm install --save js-data js-data-mongodb mongodb bson.

// Use Container instead of DataStore on the server
import {Container} from 'js-data'
import MongoDBAdapter from 'js-data-mongodb'

// Create a store to hold your Mappers
const store = new Container({
  mapperDefaults: {
    // MongoDB uses "_id" as the primary key
    idAttribute: '_id'
  }
})

// Create an instance of MongoDBAdapter with default settings
const adapter = new MongoDBAdapter()

// Mappers in "store" will use the MongoDB adapter by default
store.registerAdapter('mongodb', adapter, { default: true })

// Create a Mapper that maps to a "user" collection
store.defineMapper('user')
async function findAllAdminUsers () {
  // Find all users where "user.role" == "admin"
  return await store.findAll('user', {
    role: 'admin'
  })
}

Guides and Tutorials

Get started at http://js-data.io

API Reference Docs

Visit http://api.js-data.io.

Community

Explore the Community.

Support

Find out how to Get Support.

Contributing

Read the Contributing Guide.

License

The MIT License (MIT)

Copyright (c) 2014-2016 js-data-mongodb project authors