fix: return null if field is falsy

fixes MongoServerError: FieldPath cannot be constructed with empty string error when getObjectField is called with a falsy value
This commit is contained in:
Barış Soner Uşaklı
2025-08-22 11:06:47 -04:00
parent c16f9d6495
commit 09898b94ec
5 changed files with 21 additions and 4 deletions

View File

@@ -285,6 +285,16 @@ describe('Hash methods', () => {
});
});
it('should return null if field is falsy', async () => {
const values = await Promise.all([
db.getObjectField('hashTestObject', ''),
db.getObjectField('hashTestObject', null),
db.getObjectField('hashTestObject', false),
db.getObjectField('hashTestObject', undefined),
]);
assert.deepStrictEqual(values, [null, null, null, null]);
});
it('should return null and not error', async () => {
const data = await db.getObjectField('hashTestObject', ['field1', 'field2']);
assert.strictEqual(data, null);