-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(playgrounds): add all types playground for type testing (#462)
* add all types playground for type testing * better field names for types * DBRef is not the same as DBPointer Co-authored-by: Le Roux Bodenstein <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { Buffer } = require('node:buffer'); | ||
|
||
use('test'); | ||
|
||
// Create a document with all the BSON types. | ||
const doc = { | ||
double: new Double(1.2), // Double, 1, double | ||
string: 'Hello, world!', // String, 2, string | ||
object: { key: 'value' }, // Object, 3, object | ||
array: [1, 2, 3], // Array, 4, array | ||
binData: new Binary(Buffer.from([1, 2, 3])), // Binary data, 5, binData | ||
// Undefined, 6, undefined (deprecated) | ||
objectId: new ObjectId(), // ObjectId, 7, objectId | ||
boolean: true, // Boolean, 8, boolean | ||
date: new Date(), // Date, 9, date | ||
null: null, // Null, 10, null | ||
regex: new BSONRegExp('pattern', 'i'), // Regular Expression, 11, regex | ||
// DBPointer, 12, dbPointer (deprecated) | ||
javascript: new Code('function() {}'), // JavaScript, 13, javascript | ||
symbol: new BSONSymbol('symbol'), // Symbol, 14, symbol (deprecated) | ||
javascriptWithScope: new Code('function() {}', { foo: 1, bar: 'a' }), // JavaScript code with scope 15 "javascriptWithScope" Deprecated in MongoDB 4.4. | ||
int: new Int32(12345), // 32-bit integer, 16, "int" | ||
timestamp: new Timestamp(), // Timestamp, 17, timestamp | ||
long: new Long('123456789123456789'), // 64-bit integer, 18, long | ||
decimal: new Decimal128(Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])), // Decimal128, 19, decimal | ||
minKey: new MinKey(), // Min key, -1, minKey | ||
maxKey: new MaxKey(), // Max key, 127, maxKey | ||
|
||
binDataSubtypes: { | ||
generic: new Binary(Buffer.from([1, 2, 3]), 0), // 0 | ||
functionData: new Binary('//8=', 1), // 1 | ||
binaryOld: new Binary('//8=', 2), // 2 | ||
uuidOld: new Binary('c//SZESzTGmQ6OfR38A11A==', 3), // 3 | ||
uuid: new UUID('AAAAAAAA-AAAA-4AAA-AAAA-AAAAAAAAAAAA'), // 4 | ||
md5: new Binary('c//SZESzTGmQ6OfR38A11A==', 5), // 5 | ||
encrypted: new Binary('c//SZESzTGmQ6OfR38A11A==', 6), // 6 | ||
compressedTimeSeries: new Binary('c//SZESzTGmQ6OfR38A11A==', 0), // 7 | ||
custom: new Binary('//8=', 128), // 128 | ||
}, | ||
|
||
dbRef: new DBRef('namespace', new ObjectId()), // not actually a separate type, just a convention | ||
}; | ||
|
||
// Insert the document into the `all_types` collection. | ||
db.all_types.insertOne(doc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters