Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
variety
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
variety
Commits
f087f0e4
Commit
f087f0e4
authored
Apr 10, 2012
by
James Cropcho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
it's all called 'variety' now
parent
e0d3bac4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
17 deletions
+20
-17
variety.js
variety.js
+20
-17
No files found.
variety.js
View file @
f087f0e4
/* 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/JamesCropcho/
mongodb-schema-analyzer
for details.
Please see https://github.com/JamesCropcho/
variety
for details.
Released by Maypop Inc, © 2012, under the MIT License. */
Released by Maypop Inc, © 2012, under the MIT License. */
print
(
"Variety: A MongoDB Schema Analyzer"
)
print
(
"Version 1.0, released 10 April 2012"
)
if
(
typeof
collection
===
"undefined"
)
{
if
(
typeof
collection
===
"undefined"
)
{
throw
"You have to supply a 'collection' variable, à la --eval 'var collection =
\"
animals
\"
'"
;
throw
"You have to supply a 'collection' variable, à la --eval 'var collection =
\"
animals
\"
'"
;
}
}
...
@@ -16,7 +19,7 @@ if (typeof collection === "undefined") {
...
@@ -16,7 +19,7 @@ if (typeof collection === "undefined") {
if
(
typeof
limit
===
"undefined"
)
{
var
limit
=
db
[
collection
].
count
();
}
if
(
typeof
limit
===
"undefined"
)
{
var
limit
=
db
[
collection
].
count
();
}
print
(
"Using limit of "
+
limit
);
print
(
"Using limit of "
+
limit
);
schemaAnalyzer
CanHaveChildren
=
function
(
v
)
{
variety
CanHaveChildren
=
function
(
v
)
{
var
isArray
=
v
&&
var
isArray
=
v
&&
typeof
v
===
'object'
&&
typeof
v
===
'object'
&&
typeof
v
.
length
===
'number'
&&
typeof
v
.
length
===
'number'
&&
...
@@ -24,25 +27,25 @@ schemaAnalyzerCanHaveChildren = function (v) {
...
@@ -24,25 +27,25 @@ schemaAnalyzerCanHaveChildren = function (v) {
var
isObject
=
typeof
v
===
'object'
;
var
isObject
=
typeof
v
===
'object'
;
return
isArray
||
isObject
;
return
isArray
||
isObject
;
}
}
db
.
system
.
js
.
save
(
{
_id
:
"
schemaAnalyzerCanHaveChildren"
,
value
:
schemaAnalyzer
CanHaveChildren
}
);
db
.
system
.
js
.
save
(
{
_id
:
"
varietyCanHaveChildren"
,
value
:
variety
CanHaveChildren
}
);
schemaAnalyzer
MapRecursive
=
function
(
parentKey
,
keys
)
{
variety
MapRecursive
=
function
(
parentKey
,
keys
)
{
for
(
var
key
in
keys
)
{
for
(
var
key
in
keys
)
{
var
value
=
keys
[
key
];
var
value
=
keys
[
key
];
key
=
(
parentKey
+
"."
+
key
).
replace
(
/
\.\d
+/g
,
'.XX'
);
key
=
(
parentKey
+
"."
+
key
).
replace
(
/
\.\d
+/g
,
'.XX'
);
emit
({
key
:
key
},
{
type
:
schemaAnalyzer
TypeOf
(
value
)});
emit
({
key
:
key
},
{
type
:
variety
TypeOf
(
value
)});
if
(
schemaAnalyzer
CanHaveChildren
(
value
))
{
if
(
variety
CanHaveChildren
(
value
))
{
schemaAnalyzer
MapRecursive
(
key
,
value
);
variety
MapRecursive
(
key
,
value
);
}
}
}
}
}
}
db
.
system
.
js
.
save
({
_id
:
"
schemaAnalyzerMapRecursive"
,
value
:
schemaAnalyzer
MapRecursive
});
db
.
system
.
js
.
save
({
_id
:
"
varietyMapRecursive"
,
value
:
variety
MapRecursive
});
schemaAnalyzer
TypeOf
=
function
(
thing
)
{
variety
TypeOf
=
function
(
thing
)
{
if
(
typeof
thing
===
"undefined"
)
{
throw
"
schemaAnalyzer
TypeOf() requires an argument"
;
}
if
(
typeof
thing
===
"undefined"
)
{
throw
"
variety
TypeOf() requires an argument"
;
}
if
(
typeof
thing
!==
"object"
)
{
if
(
typeof
thing
!==
"object"
)
{
return
typeof
thing
;
return
typeof
thing
;
...
@@ -59,7 +62,7 @@ schemaAnalyzerTypeOf = function(thing) {
...
@@ -59,7 +62,7 @@ schemaAnalyzerTypeOf = function(thing) {
}
}
}
}
}
}
db
.
system
.
js
.
save
({
_id
:
"
schemaAnalyzerTypeOf"
,
value
:
schemaAnalyzer
TypeOf
});
db
.
system
.
js
.
save
({
_id
:
"
varietyTypeOf"
,
value
:
variety
TypeOf
});
map
=
function
()
{
map
=
function
()
{
var
keys
=
this
;
var
keys
=
this
;
...
@@ -71,10 +74,10 @@ map = function() {
...
@@ -71,10 +74,10 @@ map = function() {
// items in an array. -JC
// items in an array. -JC
key
=
key
.
replace
(
/
\.\d
+/g
,
'.XX'
);
key
=
key
.
replace
(
/
\.\d
+/g
,
'.XX'
);
emit
({
key
:
key
},
{
type
:
schemaAnalyzer
TypeOf
(
value
)});
emit
({
key
:
key
},
{
type
:
variety
TypeOf
(
value
)});
if
(
schemaAnalyzer
CanHaveChildren
(
value
))
{
if
(
variety
CanHaveChildren
(
value
))
{
schemaAnalyzer
MapRecursive
(
key
,
value
);
variety
MapRecursive
(
key
,
value
);
}
}
}
}
}
}
...
@@ -97,12 +100,12 @@ var resultsCollectionName = collection + "Keys";
...
@@ -97,12 +100,12 @@ var resultsCollectionName = collection + "Keys";
db
[
collection
].
mapReduce
(
map
,
reduce
,
{
db
[
collection
].
mapReduce
(
map
,
reduce
,
{
out
:
{
out
:
{
replace
:
resultsCollectionName
,
replace
:
resultsCollectionName
,
db
:
"
schemaAnalyzer
Results"
},
db
:
"
variety
Results"
},
limit
:
limit
,
limit
:
limit
,
sort
:
{
_id
:
-
1
},
sort
:
{
_id
:
-
1
},
scope
:
{
limit
:
limit
}});
scope
:
{
limit
:
limit
}});
var
resultsDB
=
db
.
getMongo
().
getDB
(
"
schemaAnalyzer
Results"
);
var
resultsDB
=
db
.
getMongo
().
getDB
(
"
variety
Results"
);
var
numDocuments
=
db
[
collection
].
count
();
var
numDocuments
=
db
[
collection
].
count
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment