root / HServer / 00.Server / 00.Program / node_modules / mongod / README.md
이력 | 보기 | 이력해설 | 다운로드 (4.07 KB)
1 |
# mongod |
---|---|
2 |
|
3 |
[](https://www.npmjs.com/package/mongod) |
4 |
[](https://travis-ci.org/BrandonZacharie/node-mongod) |
5 |
[](https://coveralls.io/github/BrandonZacharie/node-mongod?branch=master) |
6 |
[](https://github.com/BrandonZacharie/node-mongod/blob/master/LICENSE.md) |
7 |
|
8 |
Start and stop a local MongoDB server in Node.js like a boss. |
9 |
|
10 |
## Installation |
11 |
|
12 |
```Bash |
13 |
|
14 |
npm install mongod |
15 |
|
16 |
``` |
17 |
|
18 |
## Usage |
19 |
|
20 |
The constructor exported by this module optionally accepts a single argument; |
21 |
a number or string that is a port or an object for configuration. |
22 |
|
23 |
### Basic Example |
24 |
|
25 |
```JavaScript |
26 |
|
27 |
const Mongod = require('mongod'); |
28 |
|
29 |
// Simply pass the port that you want a MongoDB server to listen on. |
30 |
const server = new Mongod(27017); |
31 |
|
32 |
server.open((err) => { |
33 |
if (err === null) { |
34 |
// You may now connect a client to the MongoDB |
35 |
// server bound to port 27017. |
36 |
} |
37 |
}); |
38 |
|
39 |
``` |
40 |
|
41 |
### Configuration |
42 |
|
43 |
| Property | Type | Default | Description |
44 |
|:--------------|:--------|:--------|:----------- |
45 |
| bin | String | mongod | A path to a MongoDB server binary. |
46 |
| conf | String | | A path to a MongoDB server configuration file. |
47 |
| dbpath | String | | A path to a to store MongoDB server files. |
48 |
| storageEngine | String | | A MongoDB storage engine (i.e. wiredTiger). |
49 |
| nojournal | Boolean | false | A flag to tell MongoDB to disable journaling. |
50 |
| port | Number | 27017 | A port to bind a MongoDB server to. |
51 |
|
52 |
A MongoDB server binary must be available. If you do not have one in $PATH, |
53 |
provide a path in configuration. |
54 |
|
55 |
```JavaScript |
56 |
|
57 |
const server = new Mongod({ |
58 |
port: 27017, |
59 |
bin: '/opt/local/bin/mongod' |
60 |
}); |
61 |
|
62 |
``` |
63 |
|
64 |
You may use a MongoDB configuration file instead of configuration object |
65 |
properties that are flags (i.e. `dbpath` and `port`). If `conf` is |
66 |
provided, no flags will be passed to the binary. |
67 |
|
68 |
```JavaScript |
69 |
|
70 |
const server = new Mongod({ |
71 |
conf: '/path/to/mongodb.conf' |
72 |
}); |
73 |
|
74 |
``` |
75 |
|
76 |
### Methods |
77 |
|
78 |
For methods that accept `callback`, `callback` will receive an `Error` |
79 |
as the first argument if a problem is detected; `null`, if not. |
80 |
|
81 |
#### Mongod#open() |
82 |
|
83 |
Attempt to open a MongoDB server. Returns a `Promise`. |
84 |
|
85 |
##### Promise style `open()` |
86 |
|
87 |
``` JavaScript |
88 |
|
89 |
server.open().then(() => { |
90 |
// You may now connect to the MongoDB server. |
91 |
}); |
92 |
|
93 |
``` |
94 |
|
95 |
##### Callback style `open()` |
96 |
|
97 |
``` JavaScript |
98 |
|
99 |
server.open((err) => { |
100 |
if (err === null) { |
101 |
// You may now connect to the MongoDB server. |
102 |
} |
103 |
}); |
104 |
|
105 |
``` |
106 |
|
107 |
#### Mongod#close() |
108 |
|
109 |
Close the associated MongoDB server. Returns a `Promise`. NOTE: Disconnect |
110 |
clients prior to calling this method to avoid receiving connection |
111 |
errors from clients. |
112 |
|
113 |
##### Promise style `close()` |
114 |
|
115 |
``` JavaScript |
116 |
|
117 |
server.close().then(() => { |
118 |
// The MongoDB server is now closed. |
119 |
}); |
120 |
|
121 |
``` |
122 |
|
123 |
##### Callback style `close()` |
124 |
|
125 |
``` JavaScript |
126 |
|
127 |
server.close((err) => { |
128 |
// The MongoDB server is now closed. |
129 |
}); |
130 |
|
131 |
``` |
132 |
|
133 |
### Properties |
134 |
|
135 |
#### Mongod#isOpening |
136 |
|
137 |
Determine if the instance is starting a MongoDB server; `true` while a |
138 |
process is spawning, and/or about to be spawned, until the contained MongoDB |
139 |
server either starts or errs. |
140 |
|
141 |
#### Mongod#isRunning |
142 |
|
143 |
Determine if the instance is running a MongoDB server; `true` once a process |
144 |
has spawned and the contained MongoDB server is ready to service requests. |
145 |
|
146 |
#### Mongod#isClosing |
147 |
|
148 |
Determine if the instance is closing a MongoDB server; `true` while a |
149 |
process is being, or about to be, killed until the contained MongoDB server |
150 |
either closes or errs. |
151 |
|
152 |
### Events |
153 |
|
154 |
#### stdout |
155 |
|
156 |
Emitted when a MongoDB server prints to stdout or stderr. |
157 |
|
158 |
#### opening |
159 |
|
160 |
Emitted when attempting to start a MongoDB server. |
161 |
|
162 |
#### open |
163 |
|
164 |
Emitted when a MongoDB server becomes ready to service requests. |
165 |
|
166 |
#### closing |
167 |
|
168 |
Emitted when attempting to stop a MongoDB server. |
169 |
|
170 |
#### close |
171 |
|
172 |
Emitted when a MongoDB server closes. |
173 |
|
174 |
## Credits |
175 |
|
176 |
A special thanks to @ForbesLindesay for contributing the NPM package name. |