Skip to content

Commit ce54c2e

Browse files
committed
addressed Lucas CR comments.
1 parent b738fbd commit ce54c2e

File tree

8 files changed

+245
-138
lines changed

8 files changed

+245
-138
lines changed

README.md

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,109 @@ Make sure you have a `mongod` running on localhost on port 27017 (or change the
118118
`mongodb-schema` supports all [BSON types][bson-types].
119119
Checkout [the tests][tests] for more usage examples.
120120

121+
122+
## Schema Statistics
123+
124+
To compare schemas quantitatively we introduce the following measurable metrics on a schema:
125+
126+
### Schema Depth
127+
The schema depth is defined as the maximum number of nested levels of keys in the schema. It does not matter if the subdocuments are nested directly or as elements of an array. An empty document has a depth of 0, whereas a document with some top-level keys but no nested subdocuments has a depth of 1.
128+
129+
### Schema Width
130+
The schema width is defined as the number of individual keys, added up over all nesting levels of the schema. Array values do not count towards the schema width.
131+
132+
### Examples
133+
134+
```js
135+
{}
136+
```
137+
138+
Statistic | Value
139+
:----------- | :---:
140+
Schema Depth | 0
141+
Schema Width | 0
142+
143+
144+
```js
145+
{
146+
one: 1
147+
}
148+
```
149+
150+
Statistic | Value
151+
:----------- | :---:
152+
Schema Depth | 1
153+
Schema Width | 1
154+
155+
156+
```js
157+
{
158+
one: [
159+
"foo",
160+
"bar",
161+
{
162+
two: {
163+
three: 3
164+
}
165+
},
166+
"baz"
167+
],
168+
foo: "bar"
169+
}
170+
```
171+
172+
Statistic | Value
173+
:----------- | :---:
174+
Schema Depth | 3
175+
Schema Width | 4
176+
177+
```js
178+
{
179+
a: 1,
180+
b: false,
181+
one: {
182+
c: null,
183+
two: {
184+
three: {
185+
four: 4,
186+
e: "deepest nesting level"
187+
}
188+
}
189+
},
190+
f: {
191+
g: "not the deepest level"
192+
}
193+
}
194+
```
195+
196+
Statistic | Value
197+
:----------- | :---:
198+
Schema Depth | 4
199+
Schema Width | 10
200+
201+
202+
```js
203+
// first document
204+
{
205+
foo: [
206+
{
207+
bar: [1, 2, 3]
208+
}
209+
]
210+
},
211+
// second document
212+
{
213+
foo: 0
214+
}
215+
```
216+
217+
Statistic | Value
218+
:----------- | :---:
219+
Schema Depth | 2
220+
Schema Width | 2
221+
222+
223+
121224
## Installation
122225

123226
```
@@ -130,15 +233,18 @@ npm install --save mongodb-schema
130233
npm test
131234
```
132235

133-
## License
134-
135-
Apache 2.0
136-
137-
## Contributing
236+
## Dependencies
138237

139238
Under the hood, `mongodb-schema` uses [ampersand-state][ampersand-state] and
140239
[ampersand-collection][ampersand-collection] for modeling [Schema][schema], [Field][field]'s, and [Type][type]'s.
141240

241+
**Note:** Currently we are pinning [ampersand-state][ampersand-state] to version 4.8.2 due
242+
to a backwards-breaking change introduced in version 4.9.x. For more details, see [ampersand-state issue #226](https://github.com/AmpersandJS/ampersand-state/issues/226).
243+
244+
245+
## License
246+
247+
Apache 2.0
142248

143249

144250

bin/mongodb-schema.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,18 @@ var argv = require('yargs')
4747
type: 'boolean',
4848
descibe: 'print schema statistics to stderr'
4949
})
50-
.implies('repeat', 'stats')
51-
.describe('fast', 'use fast analysis algorithm.')
52-
.boolean('fast')
50+
.describe('native', 'use native analysis algorithm.')
51+
.boolean('native')
5352
.describe('debug', 'Enable debug messages.')
5453
.describe('version', 'Show version.')
5554
.alias('h', 'help')
5655
.describe('h', 'Show this screen.')
5756
.help('h')
5857
.wrap(100)
59-
.example('$0 localhost:27017 mongodb.fanclub --sample 1000 --repeat 5 --stats --no-output --fast',
60-
'analyze 1000 docs from the mongodb.fanclub collection with the fast parser, repeat 5 times '
58+
.example('$0 localhost:27017 mongodb.fanclub --sample 1000 --repeat 5 --stats --no-output --native',
59+
'analyze 1000 docs from the mongodb.fanclub collection with the native parser, repeat 5 times '
6160
+ 'and only show statistics.')
62-
.example('$0 localhost:27017 test.foo --format table --fast',
61+
.example('$0 localhost:27017 test.foo --format table',
6362
'analyze 100 docs from the test.foo collection and print '
6463
+ 'the schema in table form.')
6564
.argv;
@@ -139,7 +138,7 @@ mongodb.connect(uri, function(err, conn) {
139138
.once('data', function() {
140139
ts = new Date();
141140
})
142-
.pipe(schema.stream(argv.fast))
141+
.pipe(schema.stream(argv.native))
143142
.on('progress', function() {
144143
bar.tick();
145144
})
@@ -164,6 +163,7 @@ mongodb.connect(uri, function(err, conn) {
164163
console.log(output);
165164
}
166165
if (argv.stats) {
166+
console.error('execution count: ' + argv.repeat);
167167
console.error('mean time: ' + numeral(stats.mean(res))
168168
.format('0.00') + 'ms (individual results: %s)', res.toString());
169169
console.error('stdev time: ' + numeral(stats.stdev(res)).format('0.00') + 'ms');

docs/schema-stats.md

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)