diff --git a/lib/cube/genericGetter.js b/lib/cube/genericGetter.js index 8b15b3b..d9bf122 100644 --- a/lib/cube/genericGetter.js +++ b/lib/cube/genericGetter.js @@ -5,7 +5,7 @@ var myutils = require("./myutils.js"), MAX_RETURNED_RECORDS = 10000; function customQuery(collectionObj, filter, sort, limit, batchSize, streamified, documentHandler) { // set MongoDB cursor options - var cursorOptions={}, + var cursorOptions = {}, cursor, stream; @@ -28,7 +28,7 @@ function customQuery(collectionObj, filter, sort, limit, batchSize, streamified, if (streamified) { stream = cursor.sort({$natural: -1}).stream(); stream.on('data', function (document) { - documentHandler({id: document._id instanceof mongodb.ObjectID ? undefined : document._id, time: document.t, data: document.d}); + documentHandler({id: document._id, time: document.t, data: (document.d === undefined ? document.key : document.d)}); }); } else { @@ -50,7 +50,7 @@ function customQuery(collectionObj, filter, sort, limit, batchSize, streamified, // A null name indicates that there are no more results. if (document) { - documentHandler({id: document._id instanceof mongodb.ObjectID ? undefined : document._id, time: document.t, data: document.d}); + documentHandler({id: document._id, time: document.t, data: (document.d === undefined ? document.key : document.d)}); } else { documentHandler(null);