Skip to content

Commit b39a245

Browse files
committed
fix(server,brain): Use the listIndexes() command
See INT-160
1 parent 179a30a commit b39a245

File tree

2 files changed

+72
-33
lines changed

2 files changed

+72
-33
lines changed

scout-brain/lib/models/collection.js

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
var AmpersandState = require('ampersand-state');
21
var AmpersandModel = require('ampersand-model');
3-
var AmpersandCollection = require('ampersand-collection');
4-
var debug = require('debug')('scout-brain:models:collection');
5-
2+
var _ = require('underscore');
63
var types = require('../types');
7-
8-
// @todo: When schema for Index finalized in server,
9-
// make them real props here.
10-
var CollectionIndex = AmpersandState.extend({
11-
extraProperties: 'allow'
12-
});
13-
14-
var CollectionIndexes = AmpersandCollection.extend({
15-
model: CollectionIndex
16-
});
4+
var IndexCollection = require('./_index-collection');
175

186
var Collection = AmpersandModel.extend({
197
idAttribute: '_id',
@@ -23,7 +11,6 @@ var Collection = AmpersandModel.extend({
2311
required: true
2412
},
2513
database: 'string',
26-
index_sizes: 'number',
2714
document_count: 'number',
2815
document_size: 'number',
2916
storage_size: 'number',
@@ -32,8 +19,61 @@ var Collection = AmpersandModel.extend({
3219
padding_factor: 'number',
3320
extent_count: 'number',
3421
extent_last_size: 'number',
22+
/**
23+
* http://docs.mongodb.org/manual/reference/command/collStats/#collStats.userFlags
24+
*/
3525
flags_user: 'number',
36-
flags_system: 'number'
26+
flags_system: 'number',
27+
/**
28+
* Is this a capped collection?
29+
*/
30+
capped: {
31+
type: 'boolean',
32+
default: false
33+
},
34+
/**
35+
* Is this collection using power of 2 allocation?
36+
*
37+
* http://docs.mongodb.org/manual/core/storage/#power-of-2-allocation
38+
*/
39+
power_of_two: {
40+
type: 'boolean',
41+
default: true
42+
},
43+
/**
44+
* The total size in memory of all records in a collection. This value does
45+
* not include the record header, which is 16 bytes per record, but does
46+
* include the record’s padding. Additionally size does not include the
47+
* size of any indexes associated with the collection, which the
48+
* totalIndexSize field reports..
49+
*
50+
* http://docs.mongodb.org/manual/reference/command/collStats/#collStats.size
51+
*/
52+
size: 'number',
53+
/**
54+
* New in version 3.0.0.
55+
*
56+
* A document that reports data from the storage engine for each index
57+
* in the collection.
58+
*
59+
* The fields in this document are the names of the indexes, while the
60+
* values themselves are documents that contain statistics for the index
61+
* provided by the storage engine. These statistics are for
62+
* internal diagnostic use.
63+
*
64+
* http://docs.mongodb.org/manual/reference/command/collStats/#collStats.indexDetails
65+
*/
66+
index_details: 'object',
67+
/**
68+
* New in version 3.0.0.
69+
*
70+
* wiredTiger only appears when using the wiredTiger storage engine. This
71+
* document contains data reported directly by the WiredTiger engine and
72+
* other data for internal diagnostic use.
73+
*
74+
* http://docs.mongodb.org/manual/reference/command/collStats/#collStats.wiredTiger
75+
*/
76+
wired_tiger: 'object'
3777
},
3878
collections: {
3979
indexes: IndexCollection

scout-server/lib/routes/collection.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ function getCollectionFeatures(req, fn) {
2424
req.db.command({
2525
collStats: req.ns.collection
2626
}, {
27-
verbose: 1
28-
}, function(err, data) {
29-
if (err) return fn(err);
30-
31-
req.collection_features = {
32-
capped: data.capped,
33-
max: data.max,
34-
size: data.size,
35-
power_of_two: data.userFlags === 1
36-
};
37-
fn(null, req.collection_features);
38-
});
27+
verbose: 1
28+
}, function(err, data) {
29+
if (err) return fn(err);
30+
31+
req.collection_features = {
32+
capped: data.capped,
33+
max_document_count: data.max,
34+
max_document_size: data.maxSize,
35+
size: data.size,
36+
power_of_two: data.userFlags === 1,
37+
index_details: data.indexDetails || {},
38+
wired_tiger: data.wiredTiger || {}
39+
};
40+
fn(null, req.collection_features);
41+
});
3942
}
4043

4144
function getCollectionStats(req, fn) {
@@ -69,11 +72,7 @@ function getCollectionStats(req, fn) {
6972
}
7073

7174
function getCollectionIndexes(req, fn) {
72-
req.db.collection('system.indexes')
73-
.find({
74-
ns: req.ns.toString()
75-
})
76-
.toArray(fn);
75+
req.db.collection(req.ns.collection).listIndexes().toArray(fn);
7776
}
7877

7978
// @todo: Move to scount-sync.collection.fetch().

0 commit comments

Comments
 (0)