You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,17 +35,17 @@ The following options can be passed when creating a new MongoDB service:
35
35
36
36
General options:
37
37
38
-
-`collection` - The name of the collection
38
+
-`collection` - The name of the collection or an already-connected collection object. When using an object, no other options are needed. See the example below.
39
39
-`connectionString` - A MongoDB connection string
40
40
-`[_id]` (default: `"_id"`) - The id property
41
41
-`username` - MongoDB username
42
42
-`password` - MongoDB password
43
43
44
44
Connection options (when `connectionString` is not set):
45
45
46
+
-`db` (default: `"feathers"`) - The name of the database
46
47
-`host` (default: `"localhost"`) - The MongoDB host
47
48
-`port` (default: `27017`) - The MongoDB port
48
-
-`db` (default: `"feathers"`) - The name of the database
49
49
50
50
MongoDB options:
51
51
@@ -54,6 +54,25 @@ MongoDB options:
54
54
-`fsync` (default: `false`) - Don't wait for syncing to disk before acknowledgment
55
55
-`safe` (default: `false`) - Safe mode
56
56
57
+
## Sharing a MongoDB connection between services
58
+
When creating a new service, the default behavior is to create a new connection to the specified database. If you would rather share a database connection between multiple services, connect to the database then pass an already-connected collection object in on options.collection. For example:
59
+
60
+
```js
61
+
var feathers =require('feathers')
62
+
, mongo =require('mongoskin')
63
+
, mongoService =require('feathers-mongodb')
64
+
, app =feathers();
65
+
66
+
// First, make the connection.
67
+
var db =mongo.db('mongodb://localhost:27017/my-project');
68
+
69
+
// Use the same db connection in both of these services.
To extend the basic MongoDB service there are two options. Either through using [Uberproto's](https://github.com/daffl/uberproto) inheritance mechanism or by using [feathers-hooks](https://github.com/feathersjs/feathers-hooks).
0 commit comments