mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 18:52:50 +00:00
31 lines
6.2 KiB
JSON
31 lines
6.2 KiB
JSON
{
|
|
"name": "monk",
|
|
"version": "0.7.1",
|
|
"main": "lib/monk.js",
|
|
"tags": [
|
|
"mongodb",
|
|
"mongo",
|
|
"driver"
|
|
],
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git://github.com/LearnBoost/monk.git"
|
|
},
|
|
"dependencies": {
|
|
"mongoskin": "0.4.4",
|
|
"debug": "*"
|
|
},
|
|
"devDependencies": {
|
|
"mocha": "*",
|
|
"expect.js": "0.1.x"
|
|
},
|
|
"readme": "# monk\n\n[](https://secure.travis-ci.org/LearnBoost/monk)\n\nMonk is a tiny layer that provides simple yet substantial usability\nimprovements for MongoDB usage within Node.JS.\n\n```js\nvar db = require('monk')('localhost/mydb')\n , users = db.get('users')\n\nusers.index('name last');\nusers.insert({ name: 'Tobi', bigdata: {} });\nusers.find({ name: 'Loki' }, '-bigdata', function () {\n // exclude bigdata field\n});\n```\n\n## Features\n\n- Command buffering. You can start querying right away.\n- Promises built-in for all queries. Easy interoperability with modules.\n- Easy connections / configuration\n- Well-designed signatures\n- Improvements to the MongoDB APIs (eg: `findAndModify` supports the\n `update` signature style)\n- Auto-casting of `_id` in queries\n- Builds on top of [mongoskin](http://github.com/kissjs/node-mongoskin)\n- Allows to set global options or collection-level options for queries. (eg:\n `safe` is `true` by default for all queries)\n\n## How to use\n\n### Connecting\n\n#### Single server\n\n```js\nvar db = require('monk')('localhost/mydb')\n```\n\n#### Replica set\n\n```js\nvar db = require('monk')('localhost/mydb,192.168.1.1')\n```\n\n### Collections\n\n#### Getting one\n\n```js\nvar users = db.get('users')\n// users.insert(), users.update() … (see below)\n```\n\n#### Dropping\n\n```js\nusers.drop(fn);\n```\n\n### Signatures\n\n- All commands accept the simple `data[, …], fn`. For example\n - `find({}, fn)`\n - `findOne({}, fn)`\n - `update({}, {}, fn)` `findAndModify({}, {}, fn)`\n - `findById('id', fn)`\n- You can pass options in the middle: `data[, …], options, fn`\n- You can pass fields to select as an array: `data[, …], ['field', …], fn`\n- You can pass fields as a string delimited by spaces:\n `data[, …], 'field1 field2', fn`\n- To exclude a field, prefix the field name with '-':\n `data[, …], '-field1', fn`\n\n### Promises\n\nAll methods that perform an async action return a promise.\n\n```js\nvar promise = users.insert({});\npromise.type; // 'insert' in this case\npromise.error(function(err){});\npromise.on('error', function(err){});\npromise.on('success', function(doc){});\npromise.on('complete', function(err, doc){});\npromise.success(function(doc){});\n```\n\n### Indexes\n\n```js\nusers.index('name.first', fn);\nusers.index('email', { unique: true }); // unique\nusers.index('name.first name.last') // compound\nusers.index({ 'email': 1, 'password': -1 }); // compound with sort\nusers.index('email', { sparse: true }, fn); // with options\nusers.indexes(fn); // get indexes\nusers.dropIndex(name, fn); // drop an index\nusers.dropIndexes(fn); // drop all indexes\n```\n\n### Inserting\n\n```js\nusers.insert({ a: 'b' }, function (err, doc) {\n if (err) throw err;\n});\n```\n\n### Casting\n\nTo cast to `ObjectId`:\n\n```js\nusers.id() // returns new generated ObjectID\nusers.id('hexstring') // returns ObjectId\nusers.id(obj) // returns ObjectId\n```\n\n### Updating\n\n```js\nusers.update({}, {}, fn);\nusers.updateById('id', {}, fn);\n```\n\n### Finding\n\n#### Many\n\n```js\nusers.find({}, function (err, docs){});\n```\n\n#### By ID\n\n```js\nusers.findById('hex representation', function(err, doc){});\nusers.findById(oid, function(err, doc){});\n```\n\n#### Single doc\n\n`findOne` also provides the `findById` functionality.\n\n```js\nusers.findOne({ name: 'test' }).on('success', function (doc) {});\n```\n\n#### And modify\n\n```js\nusers.findAndModify({ query: {}, update: {} });\nusers.findAndModify({ _id: '' }, { $set: {} });\n```\n\n#### Streaming\n\nNote: `stream: true` is optional if you register an `each` handler in the\nsame tick. In the following example I just include it for extra clarity.\n\n```js\nusers.find({}, { stream: true })\n .each(function(doc){})\n .error(function(err){})\n .success(function(){});\n```\n\n##### Destroying a cursor\n\nOn the returned promise you can call `destroy()`. Upon the cursor\nclosing the `success` event will be emitted.\n\n### Global options\n\n```js\nvar db = require('monk')('localhost/mydb')\ndb.options.multi = true; // global multi-doc update\ndb.get('users').options.multi = false; // collection-level\n```\n\nMonk sets `safe` to `true` by default.\n\n### Query debugging\n\nIf you wish to see what queries `monk` passes to the driver, simply leverage\n[debug](http://github.com/visionmedia/debug):\n\n```bash\nDEBUG=\"monk:queries\"\n```\n\nTo see all debugging output:\n\n```bash\nDEBUG=\"monk:*\"\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 Guillermo Rauch <guillermo@learnboost.com>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
|
|
"readmeFilename": "README.md",
|
|
"description": "[](https://secure.travis-ci.org/LearnBoost/monk)",
|
|
"bugs": {
|
|
"url": "https://github.com/LearnBoost/monk/issues"
|
|
},
|
|
"_id": "monk@0.7.1",
|
|
"_from": "monk@0.7.1"
|
|
}
|