Skip to content

Commit 009d795

Browse files
committed
0.0.6 objectStartingRow looks for { now.
1 parent 20a987f commit 009d795

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

lib/index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,31 @@ var extractResult = function (result) {
7878
{
7979
re: /db.isMaster/,
8080
run: function (resultp) {
81-
return objectStartingRow3(resultp);
81+
return objectStartingRow(resultp);
8282
}
8383
},
8484
{
8585
re: /rs.conf/,
8686
run: function (resultp) {
87-
return objectStartingRow3(resultp);
87+
return objectStartingRow(resultp);
8888
}
8989
},
9090
{
9191
re: /rs.initiate/,
9292
run: function (resultp) {
93-
return objectStartingRow3(resultp);
93+
return objectStartingRow(resultp);
9494
}
9595
},
9696
{
9797
re: /rs.add/,
9898
run: function (resultp) {
99-
return objectStartingRow3(resultp);
99+
return objectStartingRow(resultp);
100100
}
101101
},
102102
{
103103
re: /rs.status/,
104104
run: function (resultp) {
105-
return objectStartingRow3(resultp);
105+
return objectStartingRow(resultp);
106106
}
107107
}
108108
];
@@ -127,13 +127,26 @@ var extractResult = function (result) {
127127
};
128128

129129

130-
var objectStartingRow3 = function (resultp) {
130+
var objectStartingRow = function (resultp) {
131131
var obj = JSON.parse(resultp.raw);
132132
var lines = obj[0].split(os.EOL);
133133
resultp.lines = _.clone(lines);
134134

135+
var jsonStartIndex = 0;
136+
for (var i = 0; i < lines.length; i++) {
137+
var line = lines[i];
138+
//console.log('line', line);
139+
if (line === '{') {
140+
jsonStartIndex = i;
141+
break;
142+
}
143+
}
144+
145+
//console.log('jsonStartIndex', jsonStartIndex);
146+
147+
135148
try {
136-
var tempArray = lines.splice(2);
149+
var tempArray = lines.splice(jsonStartIndex);
137150
//console.log('tempArray', tempArray);
138151

139152
var jsonString = tempArray.reduce(function (previousValue, currentValue) {

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.5",
3+
"version": "0.0.6",
44
"description": "A node.js wrapper for the mongo CLI",
55
"main": "lib/index.js",
66
"scripts": {

test/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,26 @@ describe('Mongo', function () {
138138
});
139139
});
140140

141+
it('command rs.status() with replica set should pass', function (done) {
142+
var mongo = new Mongo({
143+
host: 'mongodb/mongodb1:27017,mongodb2:27018,mongodb3:27019'
144+
});
145+
146+
147+
assert.isNotNull(mongo);
148+
var failed = false;
149+
var err = null;
150+
mongo.command('rs.status()').then(function (data) {
151+
console.log('data = ', util.inspect(data, {depth:10}));
152+
assert.isNotNull(data);
153+
}).finally(function () {
154+
//console.log('finally ');
155+
assert.isFalse(failed);
156+
assert.isNull(err);
157+
done();
158+
});
159+
});
160+
161+
141162
});
142163

0 commit comments

Comments
 (0)