How to use the MinKey function from bson

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

28
29
30
31
32
33
34
35
36
37

```javascript
// Example schema with a field default set to MinKey
const mySchema = new Schema({
  name: String,
  priority: { type: Schema.Types.MinKey, default: new MinKey() },
});
```

- When you need to find a document with the minimum value for a specific field.
fork icon428
star icon0
watch icon84

+ 27 other calls in file

0
1
2
3
4
5
6
7
8
9
10
'use strict';


const expect = require('chai').expect;
const bson = require('bson');
const ObjectId = bson.ObjectId;
const MinKey = bson.MinKey;
const MaxKey = bson.MaxKey;
const Binary = bson.Binary;
const BSONRegExp = bson.BSONRegExp;
const Code = bson.Code;
fork icon121
star icon761
watch icon0

+ 7 other calls in file

56
57
58
59
60
61
62
63
64
65
/** @type {import('bson').Map} */
module.exports.Map = BSONJS.Map;
/** @type {import('bson').MaxKey} */
module.exports.MaxKey = BSONJS.MaxKey;
/** @type {import('bson').MinKey} */
module.exports.MinKey = BSONJS.MinKey;
/** @type {import('bson').ObjectId} */
module.exports.ObjectId = BSONJS.ObjectId;
/** @type {import('bson').BSONRegExp} */
module.exports.BSONRegExp = BSONJS.BSONRegExp;
fork icon0
star icon0
watch icon0

+ 12 other calls in file

148
149
150
151
152
153
154
155
156
157
  const result = libBson.toString(test);
  expect(result).to.eql('{\n    symbol: {\n        value: \'test\'\n    }\n}');
});

it('should convert MinKey to string', function () {
  const test = { key: new bson.MinKey() };
  const result = libBson.toString(test);
  const test2 = libBson.toBSON(result);

  expect(test2).to.eql(test);
fork icon0
star icon0
watch icon0