uuid-mongodb
Advanced tools
Comparing version 1.0.2 to 1.1.1
@@ -29,2 +29,3 @@ const { Binary } = require('mongodb'); | ||
return stringify(uuid.read(0, uuid.length())); | ||
} else { | ||
throw Err.UnexpectedUUIDType; | ||
@@ -35,3 +36,3 @@ } | ||
function generateUUID(uuid = undefined, v = 1) { | ||
function generateUUID(uuid, v = 1) { | ||
if (v <= 0 || v > 4 || v === 2 || v === 3) throw Err.UnsupportedUUIDVersion; | ||
@@ -38,0 +39,0 @@ |
{ | ||
"name": "uuid-mongodb", | ||
"version": "1.0.2", | ||
"version": "1.1.1", | ||
"description": "", | ||
@@ -31,4 +31,4 @@ "main": "lib/index.js", | ||
"mocha": "^5.2.0", | ||
"mongodb": "^3.1.1" | ||
"mongodb": "^3.1.10" | ||
} | ||
} |
# uuid-mongodb | ||
![](https://img.shields.io/badge/status-stable-green.svg) ![](https://img.shields.io/badge/tests-passing-green.svg) ![](https://img.shields.io/badge/license-MIT-blue.svg) | ||
Generates and parses [BSON UUIDs](https://docs.mongodb.com/manual/reference/method/UUID/) for use with MongoDB. BSON UUIDs provide better performance than their string counterparts. | ||
@@ -20,2 +22,4 @@ | ||
```javascript | ||
const MUUID = require('uuid-mongodb'); | ||
# Create a v1 binary UUID | ||
@@ -33,3 +37,3 @@ const mUUID1 = MUUID.v1(); | ||
# Create a binary UUID from a MongoDb Binary | ||
# Create a binary UUID from a MongoDb Binary | ||
# This is useful to get MUUIDs helpful toString() method | ||
@@ -39,14 +43,23 @@ const mUUID3 = MUUID.from(/** MongoDb Binary of SUBTYPE_UUID */) | ||
## Example | ||
## Examples | ||
### Query | ||
#### Query using binary UUIDs | ||
```javascript | ||
const uuid = MUUID.from('393967e0-8de1-11e8-9eb6-529269fb1459'); | ||
const uuid = MUUID.from('393967e0-8de1-11e8-9eb6-529269fb1459'); | ||
return collection.then(c => | ||
c.findOne({ | ||
_id: uuid, | ||
}) | ||
); | ||
``` | ||
##### Work with binary UUIDs returned in query results | ||
```javascript | ||
return collection | ||
.then(c => | ||
c.findOne({ | ||
_id: uuid, | ||
}) | ||
) | ||
.then(c => c.findOne({ _id: uuid })) | ||
.then(doc => { | ||
const uuid = MUUID.from(doc._id).toString() | ||
// do stuff | ||
}) | ||
``` | ||
@@ -53,0 +66,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
25583
131
71
1