diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.js index 452ecf9d6e..ec8a0b9c03 100644 --- a/src/database/mongo/hash.js +++ b/src/database/mongo/hash.js @@ -156,7 +156,9 @@ module.exports = function (module) { const data = {}; fields.forEach((field) => { field = helpers.fieldToString(field); - data[field] = 1; + if (field) { + data[field] = 1; + } }); const item = await module.client.collection('objects').findOne({ _key: key }, { projection: data }); diff --git a/test/database/hash.js b/test/database/hash.js index 9ac9b3a40f..39c4e39624 100644 --- a/test/database/hash.js +++ b/test/database/hash.js @@ -406,6 +406,11 @@ describe('Hash methods', () => { done(); }); }); + + it('should not error if field is falsy', async () => { + const value = await db.isObjectField('hashTestObjectEmpty', ''); + assert.strictEqual(value, false); + }); }); @@ -427,6 +432,11 @@ describe('Hash methods', () => { done(); }); }); + + it('should not error if one field is falsy', async () => { + const values = await db.isObjectFields('hashTestObject', ['name', '']); + assert.deepStrictEqual(values, [true, false]); + }); }); describe('deleteObjectField()', () => {