mongoify
v1.1.0
Published
Converts an object with native JavaScript types and objects to MongoDB Extended JSON object
Downloads
2
Maintainers
Readme
mongoify
Converts:
{
foo: { bar: 1 },
date: new Date('2014-01-01T00:00:00Z'),
regex: /foo/i,
bla: undefined
}
To this:
{
foo: { bar: 1 },
date: { $date: '2014-01-01T00:00:00Z' },
regex: { $regex: 'foo', $options: 'i' },
bla: { $undefined: true }
}
What?
This is called MongoDB Extended JSON.
Why?
So that you can JSON.stringify
the object for easy storage or
transport.
Installation
npm install mongoify
Usage
var mongoify = require('mongoify')
var obj = { date: new Date('2014-01-01T00:00:00Z') }
mongoify(obj)
console.log(JSON.stringify(obj))
License
MIT