mongodb-schema
Advanced tools
Comparing version
@@ -7,3 +7,25 @@ var es = require('event-stream'); | ||
/** | ||
* extracts a Javascript string from a BSON type to compute unique values. | ||
* | ||
* @param {Any} value value to be converted to a string | ||
* @return {String} converted value | ||
*/ | ||
var extractStringValueFromBSON = function(value) { | ||
if (_.has(value, '_bsontype')) { | ||
if (_.includes([ 'Decimal128', 'Long' ], value._bsontype)) { | ||
return value.toString(); | ||
} | ||
if (_.includes([ 'Double', 'Int32' ], value._bsontype)) { | ||
return String(value.value); | ||
} | ||
} | ||
if (_.isString(value)) { | ||
return value; | ||
} | ||
return String(value); | ||
}; | ||
/** | ||
* Returns the type of value as a string. BSON type aware. Replaces `Object` | ||
@@ -165,3 +187,3 @@ * with `Document` to avoid naming conflicts with javascript Objects. | ||
} else if (type.values) { | ||
type.unique = _.uniq(type.values).length; | ||
type.unique = _.uniq(type.values, false, extractStringValueFromBSON).length; | ||
type.has_duplicates = type.unique !== type.values.length; | ||
@@ -168,0 +190,0 @@ } |
{ | ||
"name": "mongodb-schema", | ||
"description": "Infer the probabilistic schema for a MongoDB collection.", | ||
"version": "6.0.1", | ||
"version": "6.0.2", | ||
"author": "Thomas Rueckstiess <thomas@rueckstiess.net>", | ||
@@ -51,9 +51,9 @@ "license": "Apache-2.0", | ||
"benchmark": "^2.0.0", | ||
"bson": "^0.4.0", | ||
"bson": "^0.5.6", | ||
"coveralls": "^2.11.2", | ||
"debug": "^2.2.0", | ||
"eslint-config-mongodb-js": "^0.1.4", | ||
"eslint-config-mongodb-js": "^2.2.0", | ||
"istanbul": "^0.3.15", | ||
"mocha": "^2.0.1", | ||
"mongodb-js-precommit": "^0.1.2", | ||
"mocha": "^3.1.2", | ||
"mongodb-js-precommit": "^0.2.9", | ||
"ms": "^0.7.1", | ||
@@ -60,0 +60,0 @@ "pre-commit": "^1.0.10", |
72308
0.82%1804
1.12%