How to use the Code function from bson

Find comprehensive JavaScript bson.Code code examples handpicked from public code repositorys.

30
31
32
33
34
35
36
37
38
39
MinKey: bson.MinKey,
ObjectId: bson.ObjectId,
BSONSymbol: bson.BSONSymbol,
Timestamp: bson.Timestamp,
Code: function(c, s) {
  return new bson.Code(c, s);
},
NumberDecimal: function(s) {
  if (s === undefined) {
    s = '0';
fork icon121
star icon761
watch icon0

+ 6 other calls in file

4
5
6
7
8
9
10
11
12
13
const ObjectId = bson.ObjectId;
const MinKey = bson.MinKey;
const MaxKey = bson.MaxKey;
const Binary = bson.Binary;
const BSONRegExp = bson.BSONRegExp;
const Code = bson.Code;
const Timestamp = bson.Timestamp;
const Long = bson.Long;
const Double = bson.Double;
const Int32 = bson.Int32;
fork icon121
star icon761
watch icon0

+ 7 other calls in file

40
41
42
43
44
45
46
47
48
49
50
module.exports.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;


/** @type {import('bson').Binary} */
module.exports.Binary = BSONJS.Binary;
/** @type {import('bson').Code} */
module.exports.Code = BSONJS.Code;
/** @type {import('bson').DBRef} */
module.exports.DBRef = BSONJS.DBRef;
/** @type {import('bson').Decimal128} */
module.exports.Decimal128 = BSONJS.Decimal128;
fork icon0
star icon0
watch icon0

+ 12 other calls in file

164
165
166
167
168
169
170
171
172
173
    const test2 = libBson.toBSON(result);
    expect(test2.key._bsontype).to.eql('MaxKey');
  });

  it('should convert Code to string', function () {
    const test = { code: new bson.Code('function() { x; }') };
    const result = libBson.toString(test);
    expect(result).to.eql('{\n    code: Code(\'function() { x; }\')\n}');
  });
});
fork icon0
star icon0
watch icon0