bson-ton

0.0.1 • Public • Published

status

Information

Packagebson-ton
Description BSON/MongoDB types for ton
Node Version >= 0.4

Usage

ton = require 'ton'
require 'bson-ton'
 
str = ton.stringify {bson doc}
doc = ton.parse str

Comparison

Initial document

{
    _id: new ObjectID("4fa202c54cc3da640c000001"),
    string: "test",
    regex: /test/,
    date: new Date('1/2/1978'),
    int: 42,
    float: 33.3333,
    bool: true,
    code: new Code('console.log(i);', {
        i: 1
    }),
    long: Long.fromNumber(20),
    binary: new Binary(new Buffer("test")),
    minkey: new MinKey,
    maxkey: new MaxKey,
    double: new Double(100),
    ref: new DBRef('space', new ObjectID("4fa202c54cc3da640c000002"), 'stuff'),
    arr: [1, 2, 3]
}

ton.stringify

All types and data preserved.

{
    "_id": new ObjectID("4fa202c54cc3da640c000001"),
    "string": "test",
    "regex": /test/,
    "date": new Date("1978-01-02T07:00:00.000Z"),
    "int": 42,
    "float": 33.3333,
    "bool": true,
    "code": new Code("console.log(i);", {
        "i": 1
    }),
    "long": new Long(20, 0),
    "binary": new Binary(new Buffer("test"), "0"),
    "minkey": new MinKey(),
    "maxkey": new MaxKey(),
    "double": new Double(100),
    "ref": new DBRef("space", new ObjectID("4fa202c54cc3da640c000002"), "stuff"),
    "arr": [1, 2, 3]
}

JSON.stringify

All types and some data lost - you would have to reconstruct this manually.

{
    "_id": "4fa202c54cc3da640c000001",
    "string": "test",
    "regex": {},
    "date": "1978-01-02T07:00:00.000Z",
    "int": 42,
    "float": 33.3333,
    "bool": true,
    "code": {
        "scope": {
            "i": 1
        },
        "code": "console.log(i);"
    },
    "long": "20",
    "binary": "dGVzdA==",
    "minkey": {
        "_bsontype": "MinKey"
    },
    "maxkey": {
        "_bsontype": "MaxKey"
    },
    "double": 100,
    "ref": {
        "$ref": "space",
        "$id": "4fa202c54cc3da640c000002",
        "$db": "stuff"
    },
    "arr": [1, 2, 3]
}

LICENSE

(MIT License)

Copyright (c) 2012 Fractal contact@wearefractal.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i bson-ton

Weekly Downloads

1

Version

0.0.1

License

none

Last publish

Collaborators

  • fractal
  • yocontra