Skip to content

Commit 4828ad1

Browse files
committed
add doc for addMiddleware
1 parent f62a9ce commit 4828ad1

File tree

13 files changed

+67
-80
lines changed

13 files changed

+67
-80
lines changed

LICENCE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Automattic
3+
Copyright (c) 2012 Guillermo Rauch <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+3-24
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ db.close()
2828

2929
## Features
3030

31+
- Well-designed signatures
32+
- Easy connections / configuration
3133
- Command buffering. You can start querying right away.
3234
- Promises built-in for all queries. Easy interoperability with modules.
33-
- Easy connections / configuration
34-
- Well-designed signatures
3535
- Improvements to the MongoDB APIs (eg: `findAndModify` supports the
3636
`update` signature style)
3737
- Auto-casting of `_id` in queries
@@ -44,25 +44,4 @@ db.close()
4444

4545
## License
4646

47-
(The MIT License)
48-
49-
Copyright (c) 2012 Guillermo Rauch <[email protected]>
50-
51-
Permission is hereby granted, free of charge, to any person obtaining
52-
a copy of this software and associated documentation files (the
53-
'Software'), to deal in the Software without restriction, including
54-
without limitation the rights to use, copy, modify, merge, publish,
55-
distribute, sublicense, and/or sell copies of the Software, and to
56-
permit persons to whom the Software is furnished to do so, subject to
57-
the following conditions:
58-
59-
The above copyright notice and this permission notice shall be
60-
included in all copies or substantial portions of the Software.
61-
62-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
63-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
64-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
65-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
66-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
67-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
68-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47+
MIT

docs/Debugging.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# Query debugging
1+
# Debugging
2+
3+
To get some information on what monk is doing, use the `monk-middleware-debug`:
4+
5+
```
6+
npm install --save monk-middleware-debug
7+
```
8+
9+
```js
10+
db.addMiddleware(require('monk-middleware-debug))
11+
```
212
313
* If you wish to see what queries `monk` passes to the driver, simply leverage
414
[debug](http://github.com/visionmedia/debug):
@@ -12,13 +22,13 @@
1222
```bash
1323
DEBUG="monk:*" npm start
1424
```
15-
25+
1626
* You can also see the output from the mongo driver using `debug`:
1727
1828
```bash
1929
DEBUG="mongo:*" npm start
2030
```
21-
31+
2232
There are several separated features available on this namespace:
2333
2434
* Db: The Db instance log statements
@@ -29,9 +39,9 @@
2939
* Pool: Connection Pool specific log statements
3040
* Connection: Singular connection specific log statements
3141
* Ping: Replicaset ping inquiry log statements
32-
42+
3343
To see the output of only one of those features:
34-
44+
3545
```bash
3646
DEBUG="mongo:Cursor" npm start // will only print the Cursor log statements
3747
```

docs/manager/addMiddleware.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# `manager.addMiddleware`
2+
3+
Add a middleware to the middlewares chain.
4+
5+
#### Arguments
6+
7+
1. `middleware` *(function)*: the middleware to add the the chain
8+
9+
#### Example
10+
11+
```js
12+
db.addMiddleware(require('monk-plugin-dereference'))
13+
```

lib/collection.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ Collection.prototype.count = function (query, opts, fn) {
6565
})({options: opts, query: query, callback: fn}, 'count')
6666
}
6767

68+
Collection.prototype.createIndex = function (fields, opts, fn) {
69+
if (typeof opts === 'function') {
70+
fn = opts
71+
opts = {}
72+
}
73+
74+
return this._dispatch(function createIndex (args) {
75+
return args.col.createIndex(args.fields, args.options)
76+
})({options: opts, fields: fields, callback: fn}, 'createIndex')
77+
}
78+
6879
Collection.prototype.distinct = function (field, query, opts, fn) {
6980
if (typeof opts === 'function') {
7081
fn = opts
@@ -110,17 +121,6 @@ Collection.prototype.dropIndexes = function (fn) {
110121
})({callback: fn}, 'dropIndexes')
111122
}
112123

113-
Collection.prototype.createIndex = function (fields, opts, fn) {
114-
if (typeof opts === 'function') {
115-
fn = opts
116-
opts = {}
117-
}
118-
119-
return this._dispatch(function createIndex (args) {
120-
return args.col.createIndex(args.fields, args.options)
121-
})({options: opts, fields: fields, callback: fn}, 'createIndex')
122-
}
123-
124124
Collection.prototype.ensureIndex = function (fields, opts, fn) {
125125
if (typeof opts === 'function') {
126126
fn = opts

lib/manager.js

-14
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,9 @@ var monkDebug = Debug('monk:manager')
99
var Collection = require('./collection')
1010
var ObjectId = mongo.ObjectID
1111
var MongoClient = mongo.MongoClient
12-
var Logger = mongo.Logger
1312
var EventEmitter = require('events').EventEmitter
1413
var inherits = require('util').inherits
1514

16-
/*
17-
* Logger
18-
*/
19-
Logger.setCurrentLogger(function (msg, context) {
20-
if (context.type === 'error') {
21-
return console.error(msg)
22-
}
23-
var logger = Debug('mongo:' + context.className)
24-
logger.log = console.log.bind(console)
25-
logger(context.type.toUpperCase() + ': ' + context.message)
26-
})
27-
Logger.setLevel('debug') // set the level to `debug` so we have everything going through debug
28-
2915
var STATE = {
3016
CLOSED: 'closed',
3117
OPENING: 'opening',

middlewares/castIds/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "monk-plugin-cast-ids",
3-
"description": "A monk plugin to parse the ids",
2+
"name": "monk-middleware-cast-ids",
3+
"description": "A monk middleware to parse the ids",
44
"version": "0.2.0",
55
"main": "index.js",
66
"keywords": [
77
"monk",
8-
"plugin",
8+
"middleware",
99
"ids"
1010
],
1111
"repository": {

middlewares/fields/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "monk-plugin-fields",
3-
"description": "A monk plugin to parse the fields",
2+
"name": "monk-middleware-fields",
3+
"description": "A monk middleware to parse the fields",
44
"version": "0.2.0",
55
"main": "index.js",
66
"keywords": [
77
"monk",
8-
"plugin",
8+
"middleware",
99
"fields"
1010
],
1111
"repository": {

middlewares/handle-callback/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "monk-plugin-handle-callback",
3-
"description": "A monk plugin to handle callback",
2+
"name": "monk-middleware-handle-callback",
3+
"description": "A monk middleware to handle callback",
44
"version": "0.2.0",
55
"main": "index.js",
66
"keywords": [
77
"monk",
8-
"plugin",
8+
"middleware",
99
"callback"
1010
],
1111
"repository": {

middlewares/options/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "monk-plugin-options",
3-
"description": "A monk plugin to parse the options",
2+
"name": "monk-middleware-options",
3+
"description": "A monk middleware to parse the options",
44
"version": "0.2.0",
55
"main": "index.js",
66
"keywords": [
77
"monk",
8-
"plugin",
8+
"middleware",
99
"options"
1010
],
1111
"repository": {

middlewares/query/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "monk-plugin-query",
3-
"description": "A monk plugin to parse the query",
2+
"name": "monk-middleware-query",
3+
"description": "A monk middleware to parse the query",
44
"version": "0.2.0",
55
"main": "index.js",
66
"keywords": [
77
"monk",
8-
"plugin",
8+
"middleware",
99
"query"
1010
],
1111
"repository": {

middlewares/wait-for-connection/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "monk-plugin-wait-for-connection",
3-
"description": "A monk plugin to wait for the connection",
2+
"name": "monk-middleware-wait-for-connection",
3+
"description": "A monk middleware to wait for the connection",
44
"version": "0.2.0",
55
"main": "index.js",
66
"keywords": [
77
"monk",
8-
"plugin",
8+
"middleware",
99
"wait",
1010
"connection"
1111
],

package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
},
1919
"dependencies": {
2020
"debug": "*",
21-
"gitbook-plugin-github": "2.0.0",
2221
"mongodb": "^2.1.18",
23-
"monk-plugin-cast-ids": "^0.2.0",
24-
"monk-plugin-fields": "^0.2.0",
25-
"monk-plugin-handle-callback": "^0.2.0",
26-
"monk-plugin-options": "^0.2.0",
27-
"monk-plugin-query": "^0.2.0",
28-
"monk-plugin-wait-for-connection": "^0.2.0",
22+
"monk-middleware-cast-ids": "^0.2.0",
23+
"monk-middleware-fields": "^0.2.0",
24+
"monk-middleware-handle-callback": "^0.2.0",
25+
"monk-middleware-options": "^0.2.0",
26+
"monk-middleware-query": "^0.2.0",
27+
"monk-middleware-wait-for-connection": "^0.2.0",
2928
"object-assign": "^4.1.1"
3029
},
3130
"devDependencies": {

0 commit comments

Comments
 (0)