From b8565ec486b3a522222f6915e639aaafb79bcf50 Mon Sep 17 00:00:00 2001 From: Michael Yartsev Date: Sun, 24 Sep 2017 19:27:09 +0900 Subject: [PATCH] Serialize the id if its an ObjectID, fixes #5 --- lib/helpers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/helpers.js b/lib/helpers.js index aaeac1b..111edf9 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,6 +1,7 @@ 'use strict' const crypto = require('crypto') +const ObjectID = require('mongodb').ObjectID const idKey = '_id' @@ -45,6 +46,9 @@ function outputRecord (type, record) { // ID business. clone[primaryKey] = record[idKey] + if(ObjectID.isValid(clone[primaryKey])) { + clone[primaryKey] = clone[primaryKey].toHexString() + } // Non-native types. for (const field of Object.getOwnPropertyNames(fields)) {