Commit 0f7e101b by James Cropcho

updated current year to 2015

parent 3450117a
...@@ -27,7 +27,7 @@ We'll make a collection: ...@@ -27,7 +27,7 @@ We'll make a collection:
So, let's see what we've got here: So, let's see what we've got here:
$ mongo test --eval "var collection = 'users'" variety.js $ mongo test --eval "var collection = 'users'" variety.js
+------------------------------------------------------------+ +------------------------------------------------------------+
| key | types | occurrences | percents | | key | types | occurrences | percents |
| ------------------ | ------------ | ----------- | -------- | | ------------------ | ------------ | ----------- | -------- |
...@@ -63,7 +63,7 @@ Perhaps you want to ignore a collection's oldest documents, and only see what th ...@@ -63,7 +63,7 @@ Perhaps you want to ignore a collection's oldest documents, and only see what th
One can apply a "limit" constraint, which analyzes only the newest documents in a collection ([unless sorting](https://github.com/variety/variety#analyze-documents-sorted-in-a-particular-order)), like so: One can apply a "limit" constraint, which analyzes only the newest documents in a collection ([unless sorting](https://github.com/variety/variety#analyze-documents-sorted-in-a-particular-order)), like so:
$ mongo test --eval "var collection = 'users', limit = 1" variety.js $ mongo test --eval "var collection = 'users', limit = 1" variety.js
Let's examine the results closely: Let's examine the results closely:
+----------------------------------------------------+ +----------------------------------------------------+
...@@ -80,14 +80,14 @@ We are only examining the last document here ("limit = 1"). It belongs to Genevi ...@@ -80,14 +80,14 @@ We are only examining the last document here ("limit = 1"). It belongs to Genevi
Perhaps you have a potentially very deep nested object structure, and you don't want to see more than a few levels deep in the analysis. Perhaps you have a potentially very deep nested object structure, and you don't want to see more than a few levels deep in the analysis.
One can apply a "maxDepth" constraint, which limits the depth variety will recursively search to find new objects. One can apply a "maxDepth" constraint, which limits the depth Variety will recursively search to find new objects.
db.users.insert({name:"Walter", someNestedObject:{a:{b:{c:{d:{e:1}}}}}}); db.users.insert({name:"Walter", someNestedObject:{a:{b:{c:{d:{e:1}}}}}});
The default will traverse all the way to the bottom of that structure: The default will traverse all the way to the bottom of that structure:
$ mongo test --eval "var collection = 'users'" variety.js $ mongo test --eval "var collection = 'users'" variety.js
+----------------------------------------------------------------+ +----------------------------------------------------------------+
| key | types | occurrences | percents | | key | types | occurrences | percents |
| -------------------------- | -------- | ----------- | -------- | | -------------------------- | -------- | ----------- | -------- |
...@@ -100,7 +100,7 @@ The default will traverse all the way to the bottom of that structure: ...@@ -100,7 +100,7 @@ The default will traverse all the way to the bottom of that structure:
| someNestedObject.a.b.c.d | Object | 1 | 100 | | someNestedObject.a.b.c.d | Object | 1 | 100 |
| someNestedObject.a.b.c.d.e | Number | 1 | 100 | | someNestedObject.a.b.c.d.e | Number | 1 | 100 |
+----------------------------------------------------------------+ +----------------------------------------------------------------+
$ mongo test --eval "var collection = 'users', maxDepth = 3" variety.js $ mongo test --eval "var collection = 'users', maxDepth = 3" variety.js
+----------------------------------------------------------+ +----------------------------------------------------------+
...@@ -192,4 +192,4 @@ Much thanks also, to Kyle Banker ([@Hwaet] (https://twitter.com/#!/hwaet)) for w ...@@ -192,4 +192,4 @@ Much thanks also, to Kyle Banker ([@Hwaet] (https://twitter.com/#!/hwaet)) for w
I have every reason to believe this tool will **not** corrupt your data or harm your computer. But if I were you, I would not use it in a production environment. I have every reason to believe this tool will **not** corrupt your data or harm your computer. But if I were you, I would not use it in a production environment.
Released by Maypop Inc, © 2012-2014, under the [MIT License] (http://www.opensource.org/licenses/MIT). Released by Maypop Inc, © 2012-2015, under the [MIT License] (http://www.opensource.org/licenses/MIT).
/* Variety: A MongoDB Schema Analyzer /* Variety: A MongoDB Schema Analyzer
This tool helps you get a sense of your application's schema, as well as any This tool helps you get a sense of your application's schema, as well as any
outliers to that schema. Particularly useful when you inherit a codebase with outliers to that schema. Particularly useful when you inherit a codebase with
data dump and want to quickly learn how the data's structured. Also useful for data dump and want to quickly learn how the data's structured. Also useful for
finding rare keys. finding rare keys.
Please see https://github.com/variety/variety for details. Please see https://github.com/variety/variety for details.
Released by Maypop Inc, © 2012-2014, under the MIT License. */ Released by Maypop Inc, © 2012-2015, under the MIT License. */
var log = function(message) { var log = function(message) {
if(!__quiet) { // mongo shell param, coming from https://github.com/mongodb/mongo/blob/5fc306543cd3ba2637e5cb0662cc375f36868b28/src/mongo/shell/dbshell.cpp#L624 if(!__quiet) { // mongo shell param, coming from https://github.com/mongodb/mongo/blob/5fc306543cd3ba2637e5cb0662cc375f36868b28/src/mongo/shell/dbshell.cpp#L624
...@@ -52,10 +52,10 @@ if (typeof collection === 'undefined') { ...@@ -52,10 +52,10 @@ if (typeof collection === 'undefined') {
throw 'You have to supply a \'collection\' variable, à la --eval \'var collection = "animals"\'.\n'+ throw 'You have to supply a \'collection\' variable, à la --eval \'var collection = "animals"\'.\n'+
'Possible collection options for database specified: ' + collNames + '.\n'+ 'Possible collection options for database specified: ' + collNames + '.\n'+
'Please see https://github.com/variety/variety for details.'; 'Please see https://github.com/variety/variety for details.';
} }
if (db[collection].count() === 0) { if (db[collection].count() === 0) {
throw 'The collection specified (' + collection + ') in the database specified ('+ db +') does not exist or is empty.\n'+ throw 'The collection specified (' + collection + ') in the database specified ('+ db +') does not exist or is empty.\n'+
'Possible collection options for database specified: ' + collNames + '.'; 'Possible collection options for database specified: ' + collNames + '.';
} }
...@@ -80,13 +80,13 @@ log('Using persistResults of ' + persistResults); ...@@ -80,13 +80,13 @@ log('Using persistResults of ' + persistResults);
var varietyTypeOf = function(thing) { var varietyTypeOf = function(thing) {
if (typeof thing === 'undefined') { throw 'varietyTypeOf() requires an argument'; } if (typeof thing === 'undefined') { throw 'varietyTypeOf() requires an argument'; }
if (typeof thing !== 'object') { if (typeof thing !== 'object') {
// the messiness below capitalizes the first letter, so the output matches // the messiness below capitalizes the first letter, so the output matches
// the other return values below. -JC // the other return values below. -JC
return (typeof thing)[0].toUpperCase() + (typeof thing).slice(1); return (typeof thing)[0].toUpperCase() + (typeof thing).slice(1);
} }
else { else {
if (thing && thing.constructor === Array) { if (thing && thing.constructor === Array) {
return 'Array'; return 'Array';
} }
else if (thing === null) { else if (thing === null) {
...@@ -117,18 +117,18 @@ var varietyTypeOf = function(thing) { ...@@ -117,18 +117,18 @@ var varietyTypeOf = function(thing) {
//we assume no '.' characters in the keys, which is an OK assumption for MongoDB //we assume no '.' characters in the keys, which is an OK assumption for MongoDB
var serializeDoc = function(doc, maxDepth) { var serializeDoc = function(doc, maxDepth) {
var result = {}; var result = {};
//determining if an object is a Hash vs Array vs something else is hard //determining if an object is a Hash vs Array vs something else is hard
//returns true, if object in argument may have nested objects and makes sense to analyse its content //returns true, if object in argument may have nested objects and makes sense to analyse its content
function isHash(v) { function isHash(v) {
var isArray = Array.isArray(v); var isArray = Array.isArray(v);
var isObject = typeof v === 'object'; var isObject = typeof v === 'object';
var specialObject = v instanceof Date || var specialObject = v instanceof Date ||
v instanceof ObjectId || v instanceof ObjectId ||
v instanceof BinData; v instanceof BinData;
return !specialObject && (isArray || isObject); return !specialObject && (isArray || isObject);
} }
function serialize(document, parentKey, maxDepth){ function serialize(document, parentKey, maxDepth){
for(var key in document){ for(var key in document){
//skip over inherited properties such as string, length, etch //skip over inherited properties such as string, length, etch
...@@ -137,7 +137,7 @@ var serializeDoc = function(doc, maxDepth) { ...@@ -137,7 +137,7 @@ var serializeDoc = function(doc, maxDepth) {
} }
var value = document[key]; var value = document[key];
//objects are skipped here and recursed into later //objects are skipped here and recursed into later
//if(typeof value != 'object') //if(typeof value != 'object')
result[parentKey+key] = value; result[parentKey+key] = value;
//it's an object, recurse...only if we haven't reached max depth //it's an object, recurse...only if we haven't reached max depth
if(isHash(value) && (maxDepth > 1)) { if(isHash(value) && (maxDepth > 1)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment