Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Use the mongo API in the browser

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 node_modules
Octocat-spinner-32 test
Octocat-spinner-32 LICENCE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
README.md

clientmongo

MongoDB on the client

Example

// client.js
var clientmongo = require("clientMongo"),
    Users = clientmongo("Users", "optionalDatabaseName")

Users.insert({
    foo: "bar"
}, function () {
    Users.findOne({ foo: "bar" }, function (err, person) {
        console.log(person.foo === "bar")
    })
})

// server.js

var server = require("http").createServer(),
    dnode = require("dnode"),
    clientmongo = require("clientmongo")

dnode().use(clientmongo.middleware).listen(server)

For a full example run the unit test suite (one code base) on both the server and the client.

To clarify, you can run the exact same code that interacts with mongoDB in both the browser and the server using clientmongo

Tests

  1. Install dependencies $ npm install
  2. Run server-side tests make test
  3. Boot server for client-side tests make test-server
  4. Build client-side code for client-side tests make test-build
  5. Run tests in browser (localhost:3000) or make test-run

Documentation

The APIs match the mongo-col API and more specifically the MongoDB Collection and Cursor API.

The only things missing are the options commands on the Collection.

Auth

Auth can be implemented by passing auth tokens along in the browser

var Users = clientmongo("Users", authToken)

and by implementing auth handling in the server

/*
    authToken comes from the browser authToken
    options is the options passed over RPC, including collectionName,
        method, args, cursor data
    callback is used for async auth
*/
var clientmongo = require("clientmongo"),
    Users = clientmongo("Users")

clientmongo.auth(function (authToken, options, callback) {
    // return boolean for allowed (sync)
    return true || false
    // or return allowed or not through callback
    setTimeout(function () {
        callback(true || false)
    }, 50)
})

MIT Licenced

Something went wrong with that request. Please try again.