@salestrip/mongodb
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -81,5 +81,5 @@ 'use strict' | ||
dbModule.findById = function(id, projection = {}) { | ||
dbModule.findById = function(id, options = {}) { | ||
return collection() | ||
.findOne({_id: new ObjectId(id)}, projection) | ||
.findOne({_id: new ObjectId(id)}, options) | ||
.then((doc) => { | ||
@@ -120,5 +120,5 @@ return doc ? deserialize(doc) : {} | ||
dbModule.findOne = function(query, projection = {}) { | ||
dbModule.findOne = function(query, options = {}) { | ||
return collection() | ||
.findOne(query, projection) | ||
.findOne(query, options) | ||
.then((doc) => { | ||
@@ -125,0 +125,0 @@ return doc ? deserialize(doc) : {} |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "index.js", | ||
@@ -9,0 +9,0 @@ "author": "SalesTrip Limited", |
@@ -238,4 +238,6 @@ 'use strict' | ||
const results = await db('projects').findById(id) | ||
expect(results).not.toHaveProperty('_id') | ||
expect(results.name).toBe(project1.name) | ||
expect(results).toStrictEqual({ | ||
id: expect.any(String), | ||
name: project1.name | ||
}) | ||
}) | ||
@@ -251,2 +253,12 @@ }) | ||
}) | ||
it('accepts query options document', async () => { | ||
const [project1, project2] = projects() | ||
await this.collection.insertMany([project1, project2]) | ||
const options = {projection: {id: 1}} | ||
const results = await db('projects').findById(project1._id, options) | ||
expect(results).toStrictEqual({ | ||
id: expect.any(String) | ||
}) | ||
}) | ||
}) | ||
@@ -379,6 +391,19 @@ | ||
}) | ||
expect(results).not.toHaveProperty('_id') | ||
expect(results.name).toBe(project1.name) | ||
expect(results).toStrictEqual({ | ||
id: expect.any(String), | ||
name: project1.name | ||
}) | ||
}) | ||
it('accepts query options document', async () => { | ||
const [project1, project2] = projects() | ||
await this.collection.insertMany([project1, project2]) | ||
const query = {name: project1.name} | ||
const options = {projection: {id: 1}} | ||
const results = await db('projects').findOne(query, options) | ||
expect(results).toStrictEqual({ | ||
id: expect.any(String) | ||
}) | ||
}) | ||
it('returns null object', async () => { | ||
@@ -385,0 +410,0 @@ const results = await db('projects').findOne({name: 'whatever'}) |
31712
711