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
cecdd900
Commit
cecdd900
authored
May 25, 2012
by
James Cropcho
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7 from wfreeman/master
Check for Date, ObjectId, BinData explicitly. Remove blacklist of keys.
parents
62f56de5
1b712b00
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
23 deletions
+23
-23
README.markdown
README.markdown
+10
-7
variety.js
variety.js
+13
-16
No files found.
README.markdown
View file @
cecdd900
...
...
@@ -6,19 +6,22 @@ This lightweight tool helps you get a sense of your application's schema, as wel
We'll make a collection:
db.users.insert({name: "Tom", bio: "A nice guy.", pets: ["monkey", "fish"], someWeirdLegacyKey: "I like Ike!"});
db.users.insert({name: "Dick", bio: "I swordfight."});
db.users.insert({name: "Harry", pets: "egret"});
db.users.insert({name: "Dick", bio: "I swordfight."
, birthday: new Date("1974-03-14")
});
db.users.insert({name: "Harry", pets: "egret"
, birthday: new Date("1984-03-14")
});
db.users.insert({name: "Geneviève", bio: "Ça va?"});
db.users.insert({name: "Jim", someBinData: new BinData(2,"1234")});
So, let's see what we've got here:
$ mongo test --eval "var collection = 'users'" variety.js
{ "_id" : { "key" : "_id" }, "value" : { "types" : [ "object" ] }, "totalOccurrences" : 4, "percentContaining" : 100 }
{ "_id" : { "key" : "name" }, "value" : { "types" : [ "string" ] }, "totalOccurrences" : 4, "percentContaining" : 100 }
{ "_id" : { "key" : "bio" }, "value" : { "types" : [ "string" ] }, "totalOccurrences" : 3, "percentContaining" : 75 }
{ "_id" : { "key" : "pets" }, "value" : { "types" : [ "string", "array" ] }, "totalOccurrences" : 2, "percentContaining" : 50 }
{ "_id" : { "key" : "someWeirdLegacyKey" }, "value" : { "type" : "string" }, "totalOccurrences" : 1, "percentContaining" : 25 }
{ "_id" : { "key" : "_id" }, "value" : { "types" : [ "objectId" ] }, "totalOccurrences" : 5, "percentContaining" : 100 }
{ "_id" : { "key" : "name" }, "value" : { "types" : [ "string" ] }, "totalOccurrences" : 5, "percentContaining" : 100 }
{ "_id" : { "key" : "bio" }, "value" : { "types" : [ "string" ] }, "totalOccurrences" : 3, "percentContaining" : 60 }
{ "_id" : { "key" : "birthday" }, "value" : { "types" : [ "date" ] }, "totalOccurrences" : 2, "percentContaining" : 40 }
{ "_id" : { "key" : "pets" }, "value" : { "types" : [ "string", "array" ] }, "totalOccurrences" : 2, "percentContaining" : 40 }
{ "_id" : { "key" : "someBinData" }, "value" : { "type" : "binData" }, "totalOccurrences" : 1, "percentContaining" : 20 }
{ "_id" : { "key" : "someWeirdLegacyKey" }, "value" : { "type" : "string" }, "totalOccurrences" : 1, "percentContaining" : 20 }
_("test" is the database containing the collection we are analyzing.)_
...
...
variety.js
View file @
cecdd900
...
...
@@ -25,7 +25,10 @@ varietyCanHaveChildren = function (v) {
typeof
v
.
length
===
'number'
&&
!
(
v
.
propertyIsEnumerable
(
'length'
));
var
isObject
=
typeof
v
===
'object'
;
return
isArray
||
isObject
;
var
specialObject
=
v
instanceof
Date
||
v
instanceof
ObjectId
||
v
instanceof
BinData
;
return
!
specialObject
&&
(
isArray
||
isObject
);
}
db
.
system
.
js
.
save
(
{
_id
:
"varietyCanHaveChildren"
,
value
:
varietyCanHaveChildren
}
);
...
...
@@ -57,6 +60,15 @@ varietyTypeOf = function(thing) {
else
if
(
thing
===
null
)
{
return
"null"
;
}
else
if
(
thing
instanceof
Date
)
{
return
"date"
;
}
else
if
(
thing
instanceof
ObjectId
)
{
return
"objectId"
;
}
else
if
(
thing
instanceof
BinData
)
{
return
"binData"
;
}
else
{
return
"object"
;
}
...
...
@@ -109,10 +121,6 @@ var resultsDB = db.getMongo().getDB("varietyResults");
var
numDocuments
=
db
[
collection
].
count
();
// Using our method of retrieving keys, Mongo gets confused about the following, and
// incorrectly thinks they are keys. -JC
var
blackListKeys
=
[
"_id.equals"
,
"_id.getTimestamp"
,
"_id.isObjectId"
,
"_id.str"
,
"_id.tojson"
];
resultsDB
[
resultsCollectionName
].
find
({}).
forEach
(
function
(
key
)
{
keyName
=
key
[
"_id"
].
key
;
...
...
@@ -123,17 +131,6 @@ resultsDB[resultsCollectionName].find({}).forEach(function(key) {
return
;
}
var
blackListKeyFound
=
false
;
blackListKeys
.
forEach
(
function
(
blackListKey
)
{
if
(
keyName
===
blackListKey
)
{
resultsDB
[
resultsCollectionName
].
remove
({
"_id"
:
{
key
:
keyName
}});
blackListKeyFound
=
true
;
}
});
if
(
blackListKeyFound
)
{
return
;
}
if
(
!
(
keyName
.
match
(
/
\.
XX/
)
&&
!
keyName
.
match
(
/
\.
XX$/
)))
{
// i.e. "Unless the key's value is an array which contains arrays" -JC
// ...we do not support totalOccurrences for these keys because it is
...
...
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