expresser-mongodb
MongoDB database plugin for Expresser.
Last updated 3 years ago by igoramadas .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install expresser-mongodb 
SYNC missed versions from official npm registry.

Expresser: MongoDB Database

The Database module is a MongoDB wrapper and has 3 main methods: {{ get }}, {{ set }} and {{ del }}. There's also a {{ count }} helper that works with newer versions of MongoDB.

If the {{ settings.app.cloud }} setting is enabled, the Database module will automatically figure out the connection details for the following MongoDB services: AppFog, MongoLab, MongoHQ.

Sample code

The following example illustrates how to get a document having "username = igor" from collection "users" and duplicate it to a document having "username = igor2". Errors will be logged using the Logger module.

var expresser = require("expresser");

var setCallback = function (err, result) {
    if (err) {
        expresser.logger.error("Can't save document with username igor2.", err);
    } else {
        expresser.logger.info("Document duplicated!", result);
    }
}

var getCallback = function (err, result) {
    if (err) {
        expresser.logger.error("Can't get document with username igor.", err);
    } else {
        user = result[0];
        user.username = "igor2"; // Update the username 'igor' to 'igor2'.
        delete user["id"]; // Delete the user ID so it's created as a new document.
        expresser.database.set("users", user, setCallback);
    }
}

expresser.database.mongo.get("users", {username: "igor"}, getCallback);

For detailed info on specific features, check the annotated source on /docs/database-mongo.html

Current Tags

  • 3.0.3                                ...           latest (2 years ago)

5 Versions

  • 3.0.3                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 3.0.0-beta1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |