hapi-good-mongostore
Advanced tools
Comparing version
@@ -6,2 +6,3 @@ 'use strict' | ||
const get = require('lodash.get') | ||
const safeJson = require('./safe-json') | ||
@@ -76,6 +77,6 @@ /** | ||
if (this.conn.db) { | ||
return this.conn.collection.insertMany(records, this.insertOptions || {}) | ||
return this.conn.collection.insertMany(safeJson(records), this.insertOptions || {}) | ||
} else { | ||
return this._connect() | ||
.then(() => this.conn.collection.insertMany(records, this.insertOptions || {})) | ||
.then(() => this.conn.collection.insertMany(safeJson(records), this.insertOptions || {})) | ||
} | ||
@@ -82,0 +83,0 @@ } |
{ | ||
"name": "hapi-good-mongostore", | ||
"version": "0.3.5", | ||
"version": "0.4.0", | ||
"repository": { | ||
@@ -36,2 +36,3 @@ "type": "git", | ||
"dependencies": { | ||
"circular-json": "^0.3.1", | ||
"lodash.get": "^4.4.2", | ||
@@ -38,0 +39,0 @@ "mongodb": "^2.2.26" |
@@ -0,1 +1,3 @@ | ||
'use strict' | ||
const should = require('should') | ||
@@ -82,2 +84,26 @@ const Stream = require('stream') | ||
}) | ||
describe('handle circular json', () => { | ||
it('Should safely parse circular json', (done) => { | ||
const circularObj = { foo: 'bar' } | ||
circularObj.self = circularObj | ||
const record = { | ||
tags: ['error'], | ||
data: circularObj | ||
} | ||
const options = { batchSize: 1 } | ||
const reporter = new MongoStoreStream(url, options) | ||
const stream = readStream() | ||
stream.pipe(reporter) | ||
reporter._insert = function (records) { | ||
should(records.length).be.equal(options.batchSize) | ||
should(records[0]).be.equal(record) | ||
done() | ||
} | ||
stream.push(record) | ||
}) | ||
}) | ||
}) |
62183
1.46%14
7.69%172
17.81%3
50%+ Added
+ Added