Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions scout-brain/lib/replicaset.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ Replicaset.prototype.config = function(fn) {
// ```json
// { "capped" : true, "size" : 41943040, "autoIndexId" : false }
// ```
Replicaset.prototype.collection = function(fn) {
this.db.db('local').collection('system.namespaces').findOne({
name: 'local.oplog.rs'
}, function(err, doc) {
if (err) return fn(err);
if (!doc || !doc.options) return fn(boom.badRequest('Not a member of a replicaset.'));
fn(null, doc.options);
});
return this;
};

// TODO(kangas) INT-160 ADD TESTS, FIX FOR WIREDTIGER
// Replicaset.prototype.collection = function(fn) {
// this.db.db('local').collection('system.namespaces').findOne({
// name: 'local.oplog.rs'
// }, function(err, doc) {
// if (err) return fn(err);
// if (!doc || !doc.options) return fn(boom.badRequest('Not a member of a replicaset.'));
// fn(null, doc.options);
// });
// return this;
// };

// @api private
Replicaset.prototype._status = function(fn) {
Expand Down
91 changes: 47 additions & 44 deletions scout-server/lib/routes/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ var debug = require('debug')('scout-server:routes:_index');

module.exports = {
list: function(req, res, next) {
req.db.collection('system.indexes', function(err, col) {
col.find({
ns: req.ns.toString()
}).toArray(function(err, data) {
if (err) return next(err);
res.status(200).send(data);
});
});
// TODO(kangas) INT-160 ADD TESTS, FIX FOR WIREDTIGER
// req.db.collection('system.indexes', function(err, col) {
// col.find({
// ns: req.ns.toString()
// }).toArray(function(err, data) {
// if (err) return next(err);
// res.status(200).send(data);
// });
// });
},
get: function(req, res, next) {
var query = {
ns: req.ns.toString(),
name: req.param('index_name')
};
// TODO(kangas) INT-160 ADD TESTS, FIX FOR WIREDTIGER
// var query = {
// ns: req.ns.toString(),
// name: req.param('index_name')
// };

req.db.collection('system.indexes').findOne(query, function(err, data) {
if (err) return next(err);
if (!data) {
return next(boom.notFound('Index does not exist'));
}
res.status(200).send(data);
});
// req.db.collection('system.indexes').findOne(query, function(err, data) {
// if (err) return next(err);
// if (!data) {
// return next(boom.notFound('Index does not exist'));
// }
// res.status(200).send(data);
// });
},
destroy: function(req, res, next) {
if (req.param('index_name') === '*') {
Expand All @@ -43,35 +45,36 @@ module.exports = {
});
},
create: function(req, res, next) {
var field = req.body.field,
options = req.body.options || {};
// TODO(kangas) INT-160 ADD TESTS, FIX FOR WIREDTIGER
// var field = req.body.field,
// options = req.body.options || {};

if (!field) {
return next(boom.badRequest('No field specified.'));
}
// if (!field) {
// return next(boom.badRequest('No field specified.'));
// }

if (typeof options !== 'object') {
return next(boom.badRequest('options must be an object'));
}
// if (typeof options !== 'object') {
// return next(boom.badRequest('options must be an object'));
// }

req.db.createIndex(req.ns.collection, field, options, function(err, name) {
if (err) {
if (err.message.indexOf('bad index key pattern') > -1) {
return next(boom.badRequest('Invalid index key pattern `' + JSON.stringify(field) + '`. Should be {key: [1|-1]}'));
}
return next(err);
}
// req.db.createIndex(req.ns.collection, field, options, function(err, name) {
// if (err) {
// if (err.message.indexOf('bad index key pattern') > -1) {
// return next(boom.badRequest('Invalid index key pattern `' + JSON.stringify(field) + '`. Should be {key: [1|-1]}'));
// }
// return next(err);
// }

req.db.collection('system.indexes', function(err, col) {
col.findOne({
ns: req.ns.toString(),
name: name
}, function(err, doc) {
if (err) return next(err);
res.status(201).send(doc);
});
});
});
// req.db.collection('system.indexes', function(err, col) {
// col.findOne({
// ns: req.ns.toString(),
// name: name
// }, function(err, doc) {
// if (err) return next(err);
// res.status(201).send(doc);
// });
// });
// });
},
update: function(req, res, next) {
var field = req.body.field,
Expand Down
4 changes: 2 additions & 2 deletions scout-server/lib/routes/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ var boom = require('boom'),
debug = require('debug')('scout-server:routes:database');

function getCollectionNames(req, fn) {
req.db.collection('system.namespaces').find({}).toArray(function(err, data) {
req.db.listCollections().toArray(function(err, data) {
if (err) return fn(err);

if (!data) {
return fn(boom.notAuthorized('not authorized to view collections for this database'));
}

debug('find(system.namespaces) returned', err, data);
debug('listCollections returned', err, data);

var names = data.filter(function(ns) {
return !(ns.name.indexOf('$') >= 0 && ns.name.indexOf('.oplog.$') < 0);
Expand Down