-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
70 lines (70 loc) · 11.4 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{
"name": "mongoose",
"description": "Mongoose MongoDB ODM",
"version": "3.8.8",
"author": {
"name": "Guillermo Rauch",
"email": "guillermo@learnboost.com"
},
"keywords": [
"mongodb",
"document",
"model",
"schema",
"database",
"odm",
"data",
"datastore",
"query",
"nosql",
"orm",
"db"
],
"dependencies": {
"hooks": "0.2.1",
"mongodb": "1.3.23",
"ms": "0.1.0",
"sliced": "0.0.5",
"muri": "0.3.1",
"mpromise": "0.4.3",
"mpath": "0.1.1",
"regexp-clone": "0.0.1",
"mquery": "0.5.3"
},
"devDependencies": {
"mocha": "1.12.0",
"node-static": "0.5.9",
"dox": "0.3.1",
"jade": "0.26.3",
"highlight.js": "7.0.1",
"markdown": "0.3.1",
"promises-aplus-tests": ">= 1.0.2",
"tbd": "0.6.4",
"benchmark": "1.0.0",
"open": "0.0.3",
"async": "0.2.5"
},
"directories": {
"lib": "./lib/mongoose"
},
"scripts": {
"test": "make test"
},
"main": "./index.js",
"engines": {
"node": ">=0.6.19"
},
"bugs": {
"url": "https://github.com/learnboost/mongoose/issues/new",
"email": "mongoose-orm@googlegroups.com"
},
"repository": {
"type": "git",
"url": "git://github.com/LearnBoost/mongoose.git"
},
"homepage": "http://mongoosejs.com",
"readme": "# Mongoose\n\nMongoose is a [MongoDB](http://www.mongodb.org/) object modeling tool designed to work in an asynchronous environment.\n\n[![Build Status](https://travis-ci.org/LearnBoost/mongoose.png?branch=3.8.x)](https://travis-ci.org/LearnBoost/mongoose)\n\n## Documentation\n\n[mongoosejs.com](http://mongoosejs.com/)\n\n## Support\n\n - [Stack Overflow](http://stackoverflow.com/questions/tagged/mongoose)\n - [bug reports](https://github.com/learnboost/mongoose/issues/)\n - [help forum](http://groups.google.com/group/mongoose-orm)\n - [MongoDB support](http://www.mongodb.org/display/DOCS/Technical+Support)\n - (irc) #mongoosejs on freenode\n\n## Plugins\n\nCheck out the [plugins search site](http://plugins.mongoosejs.com/) to see hundreds of related modules from the community.\n\n## Contributors\n\nView all 100+ [contributors](https://github.com/learnboost/mongoose/graphs/contributors). Stand up and be counted as a [contributor](https://github.com/LearnBoost/mongoose/blob/master/CONTRIBUTING.md) too!\n\n## Live Examples\n<a href=\"https://runnable.com/mongoose\" target=\"_blank\"><img src=\"https://runnable.com/external/styles/assets/runnablebtn.png\" style=\"width:67px;height:25px;\"></a>\n\n## Installation\n\nFirst install [node.js](http://nodejs.org/) and [mongodb](http://www.mongodb.org/downloads). Then:\n\n```sh\n$ npm install mongoose\n```\n\n## Stability\n\nThe current stable branch is [3.8.x](https://github.com/LearnBoost/mongoose/tree/3.8.x). New (unstable) development always occurs on the [master](https://github.com/LearnBoost/mongoose/tree/master) branch.\n\n## Overview\n\n### Connecting to MongoDB\n\nFirst, we need to define a connection. If your app uses only one database, you should use `mongoose.connect`. If you need to create additional connections, use `mongoose.createConnection`.\n\nBoth `connect` and `createConnection` take a `mongodb://` URI, or the parameters `host, database, port, options`.\n\n```js\nvar mongoose = require('mongoose');\n\nmongoose.connect('mongodb://localhost/my_database');\n```\n\nOnce connected, the `open` event is fired on the `Connection` instance. If you're using `mongoose.connect`, the `Connection` is `mongoose.connection`. Otherwise, `mongoose.createConnection` return value is a `Connection`.\n\n**Important!** Mongoose buffers all the commands until it's connected to the database. This means that you don't have to wait until it connects to MongoDB in order to define models, run queries, etc.\n\n### Defining a Model\n\nModels are defined through the `Schema` interface. \n\n```js\nvar Schema = mongoose.Schema\n , ObjectId = Schema.ObjectId;\n\nvar BlogPost = new Schema({\n author : ObjectId\n , title : String\n , body : String\n , date : Date\n});\n```\n\nAside from defining the structure of your documents and the types of data you're storing, a Schema handles the definition of:\n\n* [Validators](http://mongoosejs.com/docs/validation.html) (async and sync)\n* [Defaults](http://mongoosejs.com/docs/api.html#schematype_SchemaType-default)\n* [Getters](http://mongoosejs.com/docs/api.html#schematype_SchemaType-get)\n* [Setters](http://mongoosejs.com/docs/api.html#schematype_SchemaType-set)\n* [Indexes](http://mongoosejs.com/docs/guide.html#indexes)\n* [Middleware](http://mongoosejs.com/docs/middleware.html)\n* [Methods](http://mongoosejs.com/docs/guide.html#methods) definition\n* [Statics](http://mongoosejs.com/docs/guide.html#statics) definition\n* [Plugins](http://mongoosejs.com/docs/plugins.html)\n* [pseudo-JOINs](http://mongoosejs.com/docs/populate.html)\n\nThe following example shows some of these features:\n\n```js\nvar Comment = new Schema({\n name : { type: String, default: 'hahaha' }\n , age : { type: Number, min: 18, index: true }\n , bio : { type: String, match: /[a-z]/ }\n , date : { type: Date, default: Date.now }\n , buff : Buffer\n});\n\n// a setter\nComment.path('name').set(function (v) {\n return capitalize(v);\n});\n\n// middleware\nComment.pre('save', function (next) {\n notify(this.get('email'));\n next();\n});\n```\n\nTake a look at the example in `examples/schema.js` for an end-to-end example of a typical setup.\n\n### Accessing a Model\n\nOnce we define a model through `mongoose.model('ModelName', mySchema)`, we can access it through the same function\n\n```js\nvar myModel = mongoose.model('ModelName');\n```\n\nOr just do it all at once\n\n```js\nvar MyModel = mongoose.model('ModelName', mySchema);\n```\n\nWe can then instantiate it, and save it:\n\n```js\nvar instance = new MyModel();\ninstance.my.key = 'hello';\ninstance.save(function (err) {\n //\n});\n```\n\nOr we can find documents from the same collection\n\n```js\nMyModel.find({}, function (err, docs) {\n // docs.forEach\n});\n```\n\nYou can also `findOne`, `findById`, `update`, etc. For more details check out [the docs](http://mongoosejs.com/docs/queries.html).\n\n**Important!** If you opened a separate connection using `mongoose.createConnection()` but attempt to access the model through `mongoose.model('ModelName')` it will not work as expected since it is not hooked up to an active db connection. In this case access your model through the connection you created:\n\n```js\nvar conn = mongoose.createConnection('your connection string')\n , MyModel = conn.model('ModelName', schema)\n , m = new MyModel;\nm.save(); // works\n```\n\nvs\n\n```js\nvar conn = mongoose.createConnection('your connection string')\n , MyModel = mongoose.model('ModelName', schema)\n , m = new MyModel;\nm.save(); // does not work b/c the default connection object was never connected\n```\n\n### Embedded Documents\n\nIn the first example snippet, we defined a key in the Schema that looks like:\n\n```\ncomments: [Comments]\n```\n\nWhere `Comments` is a `Schema` we created. This means that creating embedded documents is as simple as:\n\n```js\n// retrieve my model\nvar BlogPost = mongoose.model('BlogPost');\n\n// create a blog post\nvar post = new BlogPost();\n\n// create a comment\npost.comments.push({ title: 'My comment' });\n\npost.save(function (err) {\n if (!err) console.log('Success!');\n});\n```\n\nThe same goes for removing them:\n\n```js\nBlogPost.findById(myId, function (err, post) {\n if (!err) {\n post.comments[0].remove();\n post.save(function (err) {\n // do something\n });\n }\n});\n```\n\nEmbedded documents enjoy all the same features as your models. Defaults, validators, middleware. Whenever an error occurs, it's bubbled to the `save()` error callback, so error handling is a snap!\n\nMongoose interacts with your embedded documents in arrays _atomically_, out of the box.\n\n### Middleware\n\nSee the [docs](http://mongoosejs.com/docs/middleware.html) page.\n\n#### Intercepting and mutating method arguments\n\nYou can intercept method arguments via middleware.\n\nFor example, this would allow you to broadcast changes about your Documents every time someone `set`s a path in your Document to a new value:\n\n```js\nschema.pre('set', function (next, path, val, typel) {\n // `this` is the current Document\n this.emit('set', path, val);\n\n // Pass control to the next pre\n next();\n});\n```\n\nMoreover, you can mutate the incoming `method` arguments so that subsequent middleware see different values for those arguments. To do so, just pass the new values to `next`:\n\n```js\n.pre(method, function firstPre (next, methodArg1, methodArg2) {\n // Mutate methodArg1\n next(\"altered-\" + methodArg1.toString(), methodArg2);\n});\n\n// pre declaration is chainable\n.pre(method, function secondPre (next, methodArg1, methodArg2) {\n console.log(methodArg1);\n // => 'altered-originalValOfMethodArg1' \n \n console.log(methodArg2);\n // => 'originalValOfMethodArg2' \n \n // Passing no arguments to `next` automatically passes along the current argument values\n // i.e., the following `next()` is equivalent to `next(methodArg1, methodArg2)`\n // and also equivalent to, with the example method arg \n // values, `next('altered-originalValOfMethodArg1', 'originalValOfMethodArg2')`\n next();\n});\n```\n\n#### Schema gotcha\n\n`type`, when used in a schema has special meaning within Mongoose. If your schema requires using `type` as a nested property you must use object notation:\n\n```js\nnew Schema({\n broken: { type: Boolean }\n , asset : {\n name: String\n , type: String // uh oh, it broke. asset will be interpreted as String\n }\n});\n\nnew Schema({\n works: { type: Boolean }\n , asset : {\n name: String\n , type: { type: String } // works. asset is an object with a type property\n }\n});\n```\n\n### Driver access\n\nThe driver being used defaults to [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) and is directly accessible through `YourModel.collection`. **Note**: using the driver directly bypasses all Mongoose power-tools like validation, getters, setters, hooks, etc.\n\n## API Docs\n\nFind the API docs [here](http://mongoosejs.com/docs/api.html), generated using [dox](http://github.com/visionmedia/dox).\n\n## License\n\nCopyright (c) 2010 LearnBoost <dev@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",
"_id": "mongoose@3.8.8",
"_from": "mongoose@"
}