Cool! Here we should be able to connect and use the proxy and api features in a few steps.
var dbConfig = { port: 27017, host: "localhost", name: "db" } var collectionName = "users" var dbproxy = require('mongodb-proxy') var db = dbproxy.create(dbConfig) db.configure(function (config) { // register a collection "users". (check out the tutorial Register a collection for more) config.register({ name: collectionName }) })
Using Stores
var store = db.createStore('users') store.get(function (x) { x.query({ id: 'xx' }) x.fields(['firstName']) x.options({ limit: 2 }) x.single(true) x.cached() }, function (err, res) { if(err) throw err console.log(res) })
Using the Api
var api = db.createApi() api.users.get({ id: 'xx', $fields: ['firstName'], $options: { limit: 2 }, $single: true, $cached: true }, function (err, res) { if(err) throw err console.log(res) })