How to use the bson.Timestamp function in bson

To help you get started, we’ve selected a few bson 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 rueckstiess / mgeneratejs / lib / operators / timestamp.js View on Github external
module.exports = function(evaluator, options) {
  // default options
  options = evaluator(
    _.defaults(options, {
      t: chance.integer({ min: 0, max: MAX_TS }),
      i: chance.integer({ min: 0, max: MAX_TS })
    })
  );
  return new bson.Timestamp(options.t, options.i);
};
github brave / vault / src / controllers / intents.js View on Github external
var users = runtime.db.get('users')
    var intents = runtime.db.get('intents')

    user = await users.findOne({ userId: userId })
    if (!user) { return reply(boom.notFound('user entry does not exist: ' + userId)) }

    result = await helper.verify(debug, user, request.payload)
    if (result) return reply(result)

    result = await helper.sessionId2stats(runtime, userId, sessionId)
    // NB: alternatives is temporary
    reply(user.version ? helper.add_nonce_data(result) : result)

    intent = { userId: userId,
               sessionID: sessionId,
               timestamp: bson.Timestamp(),
               type: type,
               payload: underscore.extend(payload, { timestamp: timestamp })
             }
    try {
      await intents.insert(intent)
    } catch (ex) {
      debug('insert failed for intents', ex)
    }
  }
},
github mongodb / node-mongodb-native / test / unit / core / common.js View on Github external
function genClusterTime(time) {
  return {
    clusterTime: new Timestamp(time),
    signature: {
      hash: new Binary(Buffer.from('testing')),
      keyId: 42
    }
  };
}
github brave / vault / src / controllers / ad-manifest.js View on Github external
return async function (request, reply) {
    var result
    var debug = braveHapi.debug(module, request)
    var payload = request.payload
    var hostname = payload.hostname
    var siteInfo = runtime.db.get('site_info')

    try {
      await siteInfo.insert(underscore.extend(payload, { timestamp: bson.Timestamp() }))
    } catch (ex) {
      debug('insert failed for siteInfo', ex)
      return reply(boom.badData('ad-manifest entry already exists: ' + hostname))
    }

    result = await siteInfo.findOne({ hostname: hostname })
    if (!result) { return reply(boom.badImplementation('database creation failed: ' + hostname)) }
    result = underscore.extend(underscore.omit(result, '_id', 'timestamp'), { timestamp: result.timestamp.toString() })

    reply(result)
  }
},
github brave / ledger / src / controllers / publisher.js View on Github external
return async (request, reply) => {
    var result
    var debug = braveHapi.debug(module, request)
    var payload = request.payload
    var publisher = payload.publisher
    var publishers = runtime.db.get('publishersV2', debug)

    result = await publishers.findOne({ publisher: publisher })
    if (result) return reply(boom.badData('publisher identity entry already exists: ' + publisher))

    try {
      await publishers.insert(underscore.extend(payload, { timestamp: bson.Timestamp() }))
    } catch (ex) {
      runtime.notify(debug, { text: 'publishers error: ' + ex.toString() })
      debug('publishers error', ex)
      return reply(boom.badData(ex.toString()))
    }

    result = await publishers.findOne({ publisher: publisher })
    if (!result) return reply(boom.badImplementation('database creation failed: ' + publisher))

    result = underscore.extend(underscore.omit(result, [ '_id', 'timestamp' ]), { timestamp: result.timestamp.toString() })

    reply(result)
  }
},
github brave / vault / src / controllers / ad-manifest.js View on Github external
return async function (request, reply) {
    var result
    var debug = braveHapi.debug(module, request)
    var payload = request.payload
    var hostname = payload.hostname
    var siteInfo = runtime.db.get('site_info')

    try {
      await siteInfo.insert(underscore.extend(payload, { timestamp: bson.Timestamp() }))
    } catch (ex) {
      debug('insert failed for siteInfo', ex)
      return reply(boom.badData('ad-manifest entry already exists: ' + hostname))
    }

    result = await siteInfo.findOne({ hostname: hostname })
    if (!result) { return reply(boom.badImplementation('database creation failed: ' + hostname)) }
    result = underscore.extend(underscore.omit(result, '_id', 'timestamp'), { timestamp: result.timestamp.toString() })

    reply(result)
  }
},
github mongodb-js / query-parser / lib / index.js View on Github external
Timestamp: function(low, high) {
    return new bson.Timestamp(low, high);
  },
  ISODate: function(s) {
github mongodb-js / extended-json / lib / modes / strict.js View on Github external
$timestamp: function(val) {
      return bson.Timestamp(val.$timestamp.t, val.$timestamp.i);
    },
    $numberLong: function(val) {