From bce640e51485c322e25543d51403f92339d90a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 3 Mar 2018 12:31:20 -0500 Subject: [PATCH] closes #6340 --- src/database/mongo/main.js | 16 +++++++++++++++- test/database/keys.js | 8 ++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/database/mongo/main.js b/src/database/mongo/main.js index b8ceaa4f6f..55a29e6ff9 100644 --- a/src/database/mongo/main.js +++ b/src/database/mongo/main.js @@ -66,7 +66,21 @@ module.exports = function (db, module) { if (!key) { return callback(); } - module.getObjectField(key, 'data', callback); + module.getObject(key, function (err, objectData) { + if (err) { + return callback(err); + } + // fallback to old field name 'value' for backwards compatibility #6340 + var value = null; + if (objectData) { + if (objectData.hasOwnProperty('data')) { + value = objectData.data; + } else if (objectData.hasOwnProperty('value')) { + value = objectData.value; + } + } + callback(null, value); + }); }; module.set = function (key, value, callback) { diff --git a/test/database/keys.js b/test/database/keys.js index cdd8cc9ab4..6b187b4e3d 100644 --- a/test/database/keys.js +++ b/test/database/keys.js @@ -27,6 +27,14 @@ describe('Key methods', function () { }); }); + it('should return null if key does not exist', function (done) { + db.get('doesnotexist', function (err, value) { + assert.ifError(err); + assert.equal(value, null); + done(); + }); + }); + it('should return true if key exist', function (done) { db.exists('testKey', function (err, exists) { assert.ifError(err);