Skip to content

Commit cede9cf

Browse files
committed
0.0.3 rs.add()
1 parent 820c7c4 commit cede9cf

4 files changed

Lines changed: 165 additions & 37 deletions

File tree

README.md

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ mongo.command('rs.conf()').then(function (data) {
9393

9494
//data = {
9595
// command: 'mongo --host localhost --port 27017 --eval "rs.conf();"',
96-
// raw: '["MongoDB shell version: 3.2.0\\nconnecting to: localhost:27017/test\\n{\\n\\t\\"_id\\" : \\"mongodb\\",\\n\\t\\"version\\" : 1,\\n\\t\\"protocolVersion\\" : NumberLong(1),\\n\\t\\"members\\" : [\\n\\t\\t{\\n\\t\\t\\t\\"_id\\" : 0,\\n\\t\\t\\t\\"host\\" : \\"mongodb1.quobject.io:27017\\",\\n\\t\\t\\t\\"arbiterOnly\\" : false,\\n\\t\\t\\t\\"buildIndexes\\" : true,\\n\\t\\t\\t\\"hidden\\" : false,\\n\\t\\t\\t\\"priority\\" : 1,\\n\\t\\t\\t\\"tags\\" : {\\n\\t\\t\\t\\t\\n\\t\\t\\t},\\n\\t\\t\\t\\"slaveDelay\\" : NumberLong(0),\\n\\t\\t\\t\\"votes\\" : 1\\n\\t\\t}\\n\\t],\\n\\t\\"settings\\" : {\\n\\t\\t\\"chainingAllowed\\" : true,\\n\\t\\t\\"heartbeatIntervalMillis\\" : 2000,\\n\\t\\t\\"heartbeatTimeoutSecs\\" : 10,\\n\\t\\t\\"electionTimeoutMillis\\" : 10000,\\n\\t\\t\\"getLastErrorModes\\" : {\\n\\t\\t\\t\\n\\t\\t},\\n\\t\\t\\"getLastErrorDefaults\\" : {\\n\\t\\t\\t\\"w\\" : 1,\\n\\t\\t\\t\\"wtimeout\\" : 0\\n\\t\\t}\\n\\t}\\n}\\n",""]',
96+
// raw: '["MongoDB shell version: 3.2.0\\nconnecting to: localhost:27017/test\\n{\\n\\t\\"_id\\" : \\"mongodb\\",\\n\\t\\"version\\" : 1,\\n\\t\\"protocolVersion\\" : NumberLong(1),\\n\\t\\"members\\" : [\\n\\t\\t{\\n\\t\\t\\t\\"_id\\" : 0,\\n\\t\\t\\t\\"host\\" : \\"mongodb1:27017\\",\\n\\t\\t\\t\\"arbiterOnly\\" : false,\\n\\t\\t\\t\\"buildIndexes\\" : true,\\n\\t\\t\\t\\"hidden\\" : false,\\n\\t\\t\\t\\"priority\\" : 1,\\n\\t\\t\\t\\"tags\\" : {\\n\\t\\t\\t\\t\\n\\t\\t\\t},\\n\\t\\t\\t\\"slaveDelay\\" : NumberLong(0),\\n\\t\\t\\t\\"votes\\" : 1\\n\\t\\t}\\n\\t],\\n\\t\\"settings\\" : {\\n\\t\\t\\"chainingAllowed\\" : true,\\n\\t\\t\\"heartbeatIntervalMillis\\" : 2000,\\n\\t\\t\\"heartbeatTimeoutSecs\\" : 10,\\n\\t\\t\\"electionTimeoutMillis\\" : 10000,\\n\\t\\t\\"getLastErrorModes\\" : {\\n\\t\\t\\t\\n\\t\\t},\\n\\t\\t\\"getLastErrorDefaults\\" : {\\n\\t\\t\\t\\"w\\" : 1,\\n\\t\\t\\t\\"wtimeout\\" : 0\\n\\t\\t}\\n\\t}\\n}\\n",""]',
9797
// lines:
9898
// ['MongoDB shell version: 3.2.0',
9999
// 'connecting to: localhost:27017/test',
@@ -104,7 +104,7 @@ mongo.command('rs.conf()').then(function (data) {
104104
// '\t"members" : [',
105105
// '\t\t{',
106106
// '\t\t\t"_id" : 0,',
107-
// '\t\t\t"host" : "mongodb1.quobject.io:27017",',
107+
// '\t\t\t"host" : "mongodb1:27017",',
108108
// '\t\t\t"arbiterOnly" : false,',
109109
// '\t\t\t"buildIndexes" : true,',
110110
// '\t\t\t"hidden" : false,',
@@ -139,7 +139,7 @@ mongo.command('rs.conf()').then(function (data) {
139139
// members:
140140
// [{
141141
// _id: 0,
142-
// host: 'mongodb1.quobject.io:27017',
142+
// host: 'mongodb1:27017',
143143
// arbiterOnly: false,
144144
// buildIndexes: true,
145145
// hidden: false,
@@ -172,13 +172,13 @@ mongo.command('rs.initiate()').then(function (data) {
172172

173173
//data = {
174174
// command: 'mongo --host localhost --port 27017 --eval "rs.initiate()"',
175-
// raw: '["MongoDB shell version: 3.2.0\\nconnecting to: localhost:27017/test\\n{\\n\\t\\"info2\\" : \\"no configuration specified. Using a default configuration for the set\\",\\n\\t\\"me\\" : \\"mongodb1.quobject.io:27017\\",\\n\\t\\"info\\" : \\"try querying local.system.replset to see current configuration\\",\\n\\t\\"ok\\" : 0,\\n\\t\\"errmsg\\" : \\"already initialized\\",\\n\\t\\"code\\" : 23\\n}\\n",""]',
175+
// raw: '["MongoDB shell version: 3.2.0\\nconnecting to: localhost:27017/test\\n{\\n\\t\\"info2\\" : \\"no configuration specified. Using a default configuration for the set\\",\\n\\t\\"me\\" : \\"mongodb1:27017\\",\\n\\t\\"info\\" : \\"try querying local.system.replset to see current configuration\\",\\n\\t\\"ok\\" : 0,\\n\\t\\"errmsg\\" : \\"already initialized\\",\\n\\t\\"code\\" : 23\\n}\\n",""]',
176176
// lines:
177177
// ['MongoDB shell version: 3.2.0',
178178
// 'connecting to: localhost:27017/test',
179179
// '{',
180180
// '\t"info2" : "no configuration specified. Using a default configuration for the set",',
181-
// '\t"me" : "mongodb1.quobject.io:27017",',
181+
// '\t"me" : "mongodb1:27017",',
182182
// '\t"info" : "try querying local.system.replset to see current configuration",',
183183
// '\t"ok" : 0,',
184184
// '\t"errmsg" : "already initialized",',
@@ -188,11 +188,112 @@ mongo.command('rs.initiate()').then(function (data) {
188188
// object:
189189
// {
190190
// info2: 'no configuration specified. Using a default configuration for the set',
191-
// me: 'mongodb1.quobject.io:27017',
191+
// me: 'mongodb1:27017',
192192
// info: 'try querying local.system.replset to see current configuration',
193193
// ok: 0,
194194
// errmsg: 'already initialized',
195195
// code: 23
196196
// }
197197
//}
198-
```
198+
```
199+
200+
201+
* rs.conf()
202+
203+
```js
204+
205+
mongo.command('rs.conf()').then(function (data) {
206+
console.log('data = ', data);
207+
});
208+
209+
210+
//data = {
211+
// command: 'mongo --host localhost --port 27017 --eval "rs.conf();"',
212+
// raw: '["MongoDB shell version: 3.2.0\\nconnecting to: localhost:27017/test\\n{\\n\\t\\"_id\\" : \\"mongodb\\",\\n\\t\\"version\\" : 1,\\n\\t\\"protocolVersion\\" : NumberLong(1),\\n\\t\\"members\\" : [\\n\\t\\t{\\n\\t\\t\\t\\"_id\\" : 0,\\n\\t\\t\\t\\"host\\" : \\"mongodb1:27017\\",\\n\\t\\t\\t\\"arbiterOnly\\" : false,\\n\\t\\t\\t\\"buildIndexes\\" : true,\\n\\t\\t\\t\\"hidden\\" : false,\\n\\t\\t\\t\\"priority\\" : 1,\\n\\t\\t\\t\\"tags\\" : {\\n\\t\\t\\t\\t\\n\\t\\t\\t},\\n\\t\\t\\t\\"slaveDelay\\" : NumberLong(0),\\n\\t\\t\\t\\"votes\\" : 1\\n\\t\\t}\\n\\t],\\n\\t\\"settings\\" : {\\n\\t\\t\\"chainingAllowed\\" : true,\\n\\t\\t\\"heartbeatIntervalMillis\\" : 2000,\\n\\t\\t\\"heartbeatTimeoutSecs\\" : 10,\\n\\t\\t\\"electionTimeoutMillis\\" : 10000,\\n\\t\\t\\"getLastErrorModes\\" : {\\n\\t\\t\\t\\n\\t\\t},\\n\\t\\t\\"getLastErrorDefaults\\" : {\\n\\t\\t\\t\\"w\\" : 1,\\n\\t\\t\\t\\"wtimeout\\" : 0\\n\\t\\t}\\n\\t}\\n}\\n",""]',
213+
// lines:
214+
// ['MongoDB shell version: 3.2.0',
215+
// 'connecting to: localhost:27017/test',
216+
// '{',
217+
// '\t"_id" : "mongodb",',
218+
// '\t"version" : 1,',
219+
// '\t"protocolVersion" : NumberLong(1),',
220+
// '\t"members" : [',
221+
// '\t\t{',
222+
// '\t\t\t"_id" : 0,',
223+
// '\t\t\t"host" : "mongodb1:27017",',
224+
// '\t\t\t"arbiterOnly" : false,',
225+
// '\t\t\t"buildIndexes" : true,',
226+
// '\t\t\t"hidden" : false,',
227+
// '\t\t\t"priority" : 1,',
228+
// '\t\t\t"tags" : {',
229+
// '\t\t\t\t',
230+
// '\t\t\t},',
231+
// '\t\t\t"slaveDelay" : NumberLong(0),',
232+
// '\t\t\t"votes" : 1',
233+
// '\t\t}',
234+
// '\t],',
235+
// '\t"settings" : {',
236+
// '\t\t"chainingAllowed" : true,',
237+
// '\t\t"heartbeatIntervalMillis" : 2000,',
238+
// '\t\t"heartbeatTimeoutSecs" : 10,',
239+
// '\t\t"electionTimeoutMillis" : 10000,',
240+
// '\t\t"getLastErrorModes" : {',
241+
// '\t\t\t',
242+
// '\t\t},',
243+
// '\t\t"getLastErrorDefaults" : {',
244+
// '\t\t\t"w" : 1,',
245+
// '\t\t\t"wtimeout" : 0',
246+
// '\t\t}',
247+
// '\t}',
248+
// '}',
249+
// ''],
250+
// object:
251+
// {
252+
// _id: 'mongodb',
253+
// version: 1,
254+
// protocolVersion: { '$numberLong': '1),' },
255+
// members:
256+
// [{
257+
// _id: 0,
258+
// host: 'mongodb1:27017',
259+
// arbiterOnly: false,
260+
// buildIndexes: true,
261+
// hidden: false,
262+
// priority: 1,
263+
// tags: {},
264+
// slaveDelay: { '$numberLong': '0),' },
265+
// votes: 1
266+
// }],
267+
// settings:
268+
// {
269+
// chainingAllowed: true,
270+
// heartbeatIntervalMillis: 2000,
271+
// heartbeatTimeoutSecs: 10,
272+
// electionTimeoutMillis: 10000,
273+
// getLastErrorModes: {},
274+
// getLastErrorDefaults: { w: 1, wtimeout: 0 }
275+
// }
276+
// }
277+
//}
278+
```
279+
280+
* rs.add()
281+
282+
```js
283+
284+
mongo.command('rs.add(\'mongodb2:27017\')').then(function (data) {
285+
console.log('data = ', data);
286+
});
287+
288+
//data = {
289+
// command: 'mongo --host localhost --port 27017 --eval "rs.add(\'mongodb2:27017\')"',
290+
// raw: '["MongoDB shell version: 3.2.0\\nconnecting to: localhost:27017/test\\n{ \\"ok\\" : 1 }\\n",""]',
291+
// lines:
292+
// ['MongoDB shell version: 3.2.0',
293+
// 'connecting to: localhost:27017/test',
294+
// '{ "ok" : 1 }',
295+
// ''],
296+
// object: { ok: 1 }
297+
//}
298+
299+
```

lib/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,25 @@ var extractResult = function (result) {
7676

7777
var extracterArray = [
7878
{
79-
re: /db.isMaster()/,
79+
re: /db.isMaster/,
8080
run: function (resultp) {
8181
return objectStartingRow3(resultp);
8282
}
8383
},
8484
{
85-
re: /rs.conf()/,
85+
re: /rs.conf/,
8686
run: function (resultp) {
8787
return objectStartingRow3(resultp);
8888
}
8989
},
9090
{
91-
re: /rs.initiate()/,
91+
re: /rs.initiate/,
92+
run: function (resultp) {
93+
return objectStartingRow3(resultp);
94+
}
95+
},
96+
{
97+
re: /rs.add/,
9298
run: function (resultp) {
9399
return objectStartingRow3(resultp);
94100
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongo-cli-js",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A node.js wrapper for the mongo CLI",
55
"main": "lib/index.js",
66
"scripts": {

test/index.js

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,39 @@ describe('Mongo', function () {
3232
//});
3333

3434

35-
//it('command db.isMaster() should pass', function (done) {
35+
it('command db.isMaster() should pass', function (done) {
36+
var mongo = new Mongo({
37+
host: 'localhost',
38+
port: 27017
39+
});
40+
41+
42+
assert.isNotNull(mongo);
43+
var failed = false;
44+
var err = null;
45+
mongo.command('db.isMaster()').then(function (data) {
46+
console.log('data = ', data);
47+
assert.isNotNull(data);
48+
}).finally(function () {
49+
//console.log('finally ');
50+
assert.isFalse(failed);
51+
assert.isNull(err);
52+
done();
53+
});
54+
});
55+
56+
57+
//it('command rs.conf(); should pass', function (done) {
3658
// var mongo = new Mongo({
3759
// host: 'localhost',
3860
// port: 27017
3961
// });
4062

41-
4263
// assert.isNotNull(mongo);
4364
// var failed = false;
4465
// var err = null;
45-
// mongo.command('db.isMaster()').then(function (data) {
46-
// console.log('data = ', data);
66+
// mongo.command('rs.conf()').then(function (data) {
67+
// console.log('data = ', util.inspect(data, {depth:10}));
4768
// assert.isNotNull(data);
4869
// }).finally(function () {
4970
// //console.log('finally ');
@@ -53,8 +74,7 @@ describe('Mongo', function () {
5374
// });
5475
//});
5576

56-
57-
//it('command rs.conf(); should pass', function (done) {
77+
//it('command rs.initiate(); should pass', function (done) {
5878
// var mongo = new Mongo({
5979
// host: 'localhost',
6080
// port: 27017
@@ -64,8 +84,8 @@ describe('Mongo', function () {
6484
// assert.isNotNull(mongo);
6585
// var failed = false;
6686
// var err = null;
67-
// mongo.command('rs.conf()').then(function (data) {
68-
// console.log('data = ', util.inspect(data, {depth:10}));
87+
// mongo.command('rs.initiate()').then(function (data) {
88+
// console.log('data = ', util.inspect(data, { depth: 10 }));
6989
// assert.isNotNull(data);
7090
// }).finally(function () {
7191
// //console.log('finally ');
@@ -75,28 +95,29 @@ describe('Mongo', function () {
7595
// });
7696
//});
7797

78-
it('command rs.initiate(); should pass', function (done) {
79-
var mongo = new Mongo({
80-
host: 'localhost',
81-
port: 27017
82-
});
8398

99+
//it('command rs.add(); should pass', function (done) {
100+
// var mongo = new Mongo({
101+
// host: 'localhost',
102+
// port: 27017
103+
// });
84104

85-
assert.isNotNull(mongo);
86-
var failed = false;
87-
var err = null;
88-
mongo.command('rs.initiate()').then(function (data) {
89-
console.log('data = ', util.inspect(data, { depth: 10 }));
90-
assert.isNotNull(data);
91-
}).finally(function () {
92-
//console.log('finally ');
93-
assert.isFalse(failed);
94-
assert.isNull(err);
95-
done();
96-
});
97-
});
98105

106+
// assert.isNotNull(mongo);
107+
// var failed = false;
108+
// var err = null;
109+
// mongo.command('rs.add(\'mongodb2:27017\')').then(function (data) {
110+
// console.log('data = ', util.inspect(data, { depth: 10 }));
111+
// assert.isNotNull(data);
112+
// }).finally(function () {
113+
// //console.log('finally ');
114+
// assert.isFalse(failed);
115+
// assert.isNull(err);
116+
// done();
117+
// });
118+
//});
99119

100120

101121

102122
});
123+

0 commit comments

Comments
 (0)