Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-extended-json

Package Overview
Dependencies
Maintainers
20
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-extended-json

MongoDB Extended JSON.

  • 1.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-29.12%
Maintainers
20
Weekly downloads
 
Created
Source

mongodb-extended-json

MongoDB Extended JSON.

Example

var EJSON = require('mongodb-extended-json');
var BSON = require('bson');

var doc = {
  _id: BSON.ObjectID(),
  last_seen_at: new Date(),
  display_name: undefined
};

console.log('Doc', doc);
// > Doc { _id: 53c2ab5e4291b17b666d742a, last_seen_at: Sun Jul 13 2014 11:53:02 GMT-0400 (EDT), display_name: undefined }

console.log('JSON', JSON.stringify(doc));
// > JSON {"_id":"53c2ab5e4291b17b666d742a","last_seen_at":"2014-07-13T15:53:02.008Z"}

console.log('EJSON', EJSON.stringify(doc));
// > EJSON {"_id":{"$oid":"53c2ab5e4291b17b666d742a"},"last_seen_at":{"$date":1405266782008},"display_name":{"$undefined":true}}

// And likewise, EJSON.parse works just as you would expect.
EJSON.parse('{"_id":{"$oid":"53c2ab5e4291b17b666d742a"},"last_seen_at":{"$date":1405266782008},"display_name":{"$undefined":true}}');
// { _id: 53c2ab5e4291b17b666d742a,
//   last_seen_at: Sun Jul 13 2014 11:53:02 GMT-0400 (EDT),
//  display_name: undefined }

Streams

var request = require('request');
var url = 'https://cdn.rawgit.com/imlucas/mongodb-extended-json/master/test/data.json';
var EJSON = require('./');
var util = require('util');
var es = require('event-stream');

request.get(url)
  .pipe(EJSON.createParseStream('*'))
  .pipe(es.through(function(doc){
    this.emit('data',
      util.format('_id `%s` has timestamp %s\n', doc._id, doc._id.getTimestamp()));
  }))
  .pipe(process.stdout);

// Prints out:
//
// _id `54a1e4c798c1120000bb8b0f` has timestamp Mon Dec 29 2014 18:33:27 GMT-0500 (EST)
// _id `54a1e42f94042000008ac2f3` has timestamp Mon Dec 29 2014 18:30:55 GMT-0500 (EST)
// _id `54a1e3e68f038b0000631fe2` has timestamp Mon Dec 29 2014 18:29:42 GMT-0500 (EST)
// _id `54a1e3bc124968000052af15` has timestamp Mon Dec 29 2014 18:29:00 GMT-0500 (EST)
// _id `54a1e3a8124968000052af14` has timestamp Mon Dec 29 2014 18:28:40 GMT-0500 (EST)
// _id `54a1e2117b93d000002ee9bb` has timestamp Mon Dec 29 2014 18:21:53 GMT-0500 (EST)
// _id `54a1e1d6360382000019c110` has timestamp Mon Dec 29 2014 18:20:54 GMT-0500 (EST)
// _id `54a1e12ea5a5bb0000561dda` has timestamp Mon Dec 29 2014 18:18:06 GMT-0500 (EST)
// _id `54a1e0c14f3dc50000ba1afc` has timestamp Mon Dec 29 2014 18:16:17 GMT-0500 (EST)
// _id `54a1df90edbfd100001943b3` has timestamp Mon Dec 29 2014 18:11:12 GMT-0500 (EST)

Keywords

FAQs

Package last updated on 27 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc