How to use the bson.ObjectId 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 flow-typed / flow-typed / definitions / npm / bson_v1.x.x / test_bson-v1.js View on Github external
// @flow

import BSON from "bson";
import { ObjectId } from "bson";

const bson = new BSON();
bson.serialize({ foo: "bar" });

// $ExpectError missing arg to serialize
bson.serialize();
// $ExpectError missing method
bson.wrong();

const id = new ObjectId();

id.toString();
// $ExpectError
id.wrong();

// $ExpectError
const wrongId = new ObjectId({});
github crawlab-team / artipub / spiders / juejin / juejin_spider.js View on Github external
const run = async () => {
    // 获取当前文章
    const article = await Article.findOne({ _id: bson.ObjectId(articleId) })
    if (!article) {
        process.exit(1)
    }

    const pcr = await PCR({
        revision: "",
        detectionPath: "",
        folderName: '.chromium-browser-snapshots',
        hosts: ["https://storage.googleapis.com", "https://npm.taobao.org/mirrors"],
        retry: 3,
        silent: false
    })

    // 获取浏览器
    const browser = await (pcr.puppeteer.launch({
        executablePath: pcr.executablePath,
github mongodb-js / compass-aggregations / src / components / aggregations / aggregations.stories.js View on Github external
documents: SOLAR_SYSTEM_DOCUMENTS
  },
  namespace: 'aggregations.solarSystem',
  pipeline: [
    {
      ...STAGE_DEFAULTS,
      id: new ObjectId().toHexString(),
      previewDocuments: MATCHING_SOLAR_SYSTEM_DOCUMENTS,
      stageOperator: '$match',
      stage: `{
  type: "Terrestrial planet"
}`
    },
    {
      ...STAGE_DEFAULTS,
      id: new ObjectId().toHexString(),
      previewDocuments: [{ 'terrestrial planets': 4 }],
      stageOperator: '$count',
      stage: '"terrestrial planets"'
    }
  ]
};

// gathering stats when items are in an array using $project accumulators
const ARRAY_STATS_EXAMPLE = {
  ...EXAMPLE,
  namespace: 'aggregations.solarSystem',
  pipeline: [
    {
      id: 0,
      stageOperator: '$project',
      stage: `{
github Hughp135 / angular-5-chat-app / back-end / src / api / auth / register.spec.ts View on Github external
describe('api/auth/register', () => {
  const sandbox = sinon.sandbox.create();
  const defaultServerId = new ObjectId().toHexString();

  before(async () => {
    await mongoose.connect('mongodb://localhost/myapp-test');
  });
  beforeEach(() => {
  });
  after(async () => {
    mongoose.connection.close();
  });
  afterEach(async () => {
    await User.remove({});
    sandbox.restore();
  });
  it('returns 400 with invalid data', async () => {
    return supertest(app.listen(null))
      .post('/api/register')
github Hughp135 / osustuff-tournaments / back-end / src / helpers / create-score.ts View on Github external
function createScoreData(user: IUser, params: IScoreDataArguments) {
  return {
    gameId: params.game === undefined ? new ObjectId() : params.game._id,
    score: params.score === undefined ? 10 : params.score,
    username: user.username,
    roundId: new ObjectId(),
    userId: user._id,
    rank: params.rank === undefined ? 'S' : params.rank,
    mods: params.mods === undefined ? 0 : params.mods,
    maxCombo: params.maxCombo === undefined ? 100 : params.maxCombo,
    accuracy: params.accuracy === undefined ? 99 : params.accuracy,
    misses: params.misses === undefined ? 0 : params.misses,
    count100: 1,
    date: new Date(),
    passedRound: true,
  };
}
github mongodb-js / compass-aggregations / src / components / aggregations / aggregations.stories.js View on Github external
orbitalPeriod: { value: 0.615, units: 'years' },
    eccentricity: 0.0067,
    meanOrbitalVelocity: { value: 35.02, units: 'km/sec' },
    rotationPeriod: { value: 243.69, units: 'days' },
    inclinationOfAxis: { value: 177.36, units: 'degrees' },
    meanTemperature: 465,
    gravity: { value: 8.87, units: 'm/s^2' },
    escapeVelocity: { value: 10.36, units: 'km/sec' },
    meanDensity: 5.25,
    atmosphericComposition: 'CO2',
    numberOfMoons: 0,
    hasRings: false,
    hasMagneticField: false
  },
  {
    _id: new ObjectId('59a06674c8df9f3cd2ee7d52'),
    name: 'Mercury',
    type: 'Terrestrial planet',
    orderFromSun: 1,
    radius: { value: 4879, units: 'km' },
    mass: { value: 3.3e23, units: 'kg' },
    sma: { value: 57910000, units: 'km' },
    orbitalPeriod: { value: 0.24, units: 'years' },
    eccentricity: 0.2056,
    meanOrbitalVelocity: { value: 47.36, units: 'km/sec' },
    rotationPeriod: { value: 58.65, units: 'days' },
    inclinationOfAxis: { value: 0, units: 'degrees' },
    meanTemperature: 125,
    gravity: { value: 3.24, units: 'm/s^2' },
    escapeVelocity: { value: 4.25, units: 'km/sec' },
    meanDensity: 5.43,
    atmosphericComposition: '',
github mongodb-js / compass-aggregations / src / components / aggregations / aggregations.stories.js View on Github external
const STAGE_DEFAULTS = {
  previewDocuments: [],
  isExpanded: true,
  error: null,
  syntaxError: '',
  isValid: true,
  isEnabled: true,
  isLoading: false,
  isComplete: true
};

import { ObjectId } from 'bson';

const SOLAR_SYSTEM_DOCUMENTS = [
  {
    _id: new ObjectId('59a06674c8df9f3cd2ee7d54'),
    name: 'Earth',
    type: 'Terrestrial planet',
    orderFromSun: 3,
    radius: { value: 6378.137, units: 'km' },
    mass: { value: 5.9723e24, units: 'kg' },
    sma: { value: 149600000, units: 'km' },
    orbitalPeriod: { value: 1, units: 'years' },
    eccentricity: 0.0167,
    meanOrbitalVelocity: { value: 29.78, units: 'km/sec' },
    rotationPeriod: { value: 1, units: 'days' },
    inclinationOfAxis: { value: 23.45, units: 'degrees' },
    meanTemperature: 15,
    gravity: { value: 9.8, units: 'm/s^2' },
    escapeVelocity: { value: 11.18, units: 'km/sec' },
    meanDensity: 5.52,
    atmosphericComposition: 'N2+O2',
github crawlab-team / artipub / routes / article.js View on Github external
addArticleTask: async (req, res) => {
    let task = new models.Task({
      articleId: ObjectId(req.params.id),
      platformId: ObjectId(req.body.platformId),
      status: constants.status.NOT_STARTED,
      createTs: new Date(),
      updateTs: new Date(),
      category: req.body.category,
      tag: req.body.tag,
    })
    task = await task.save()
    await res.json({
      status: 'ok',
      data: task,
    })
  },
}
github heineiuo / seashell / src / SeashellClient.js View on Github external
request = (originUrl, requestOptions = {}, callback) => {
    const connectionId = ObjectId().toString()
    while (originUrl[0] === '/') {
      originUrl = originUrl.substr(1)
    }
    const firstSlash = originUrl.indexOf('/')
    const url = firstSlash === -1 ? '/' : originUrl.substr(firstSlash)
    const hostname = firstSlash === -1 ? originUrl : originUrl.substring(0, firstSlash)
    const headers = Object.assign({}, requestOptions.headers, {
      'x-seashell-hostname': hostname,
      'x-seashell-connection-id': connectionId,
      'x-seashell-url': url,
      'x-seashell-guard': 'request-chunk'
    })

    const _write = (chunk, extHeaders = {}) => {
      const json = {
        headers: Object.assign({}, headers, extHeaders),
github twers / Viff-Service / lib / builds / builds.js View on Github external
Builds.prototype.all = function(jobid, fn) {
  jobid = _.isString(jobid) ? new ObjectId(jobid) : jobid;
  var promise = cruder.all(jobid)
                      .then(function(result) {
                        return result.map(function(build) {
                          return new Build(build);
                        });
                      });

  if (fn) {
    promise
      .then(function(result) { fn(null, result); })
      .catch(fn);
  }

  return promise;
};