How to use bson-ext - 5 common examples

To help you get started, we’ve selected a few bson-ext examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thomas4019 / pgmongo / test / util.js View on Github external
it('array of ids', function () {
    assert.deepEqual(getArrayPaths({ arr: [BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c30'), BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c32')] }), ['arr'])
  })
  it('object with mixed', function () {
github thomas4019 / pgmongo / test / util.js View on Github external
it('object with mixed', function () {
    assert.deepEqual(describeTypes({ a: '123', id2: BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c30') }), { id2: 'ObjectID'})
  })
})
github thomas4019 / pgmongo / test / util.js View on Github external
it('array of ids', function () {
    assert.deepEqual(describeTypes({ arr: [BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c30'), BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c32')] }), { arr: ['ObjectID'] })
  })
  it('object with mixed', function () {
github thomas4019 / pgmongo / index.js View on Github external
const convertToBSON = function(doc) {
  if (doc && doc._id && doc._id.length === 24) {
    doc._id = BSON.ObjectID(doc._id)
  }
  return doc
}
github thomas4019 / pgmongo / util.js View on Github external
const BSON = require('bson-ext')
const Long = BSON.Long
const _ = require('lodash')

exports.describeTypes = function (doc) {
  if (doc._bsontype) {
    return doc._bsontype
  } else if (Array.isArray(doc)) {
    const types = doc.map(exports.describeTypes)
    const uniqueTypes = _.uniqWith(types, _.isEqual)
    if (uniqueTypes.length > 1) {
      //throw new Error('arrays containing multiple data types are not allowed')
    }
    if (_.isUndefined(uniqueTypes[0])) {
      return []
    }
    return uniqueTypes
  } else if (typeof doc === 'object') {

bson-ext

The C++ bson parser for the node.js mongodb driver.

Apache-2.0
Latest version published 2 years ago

Package Health Score

42 / 100
Full package analysis

Popular bson-ext functions