Type | Number | Alias | Notes |
---|---|---|---|
Double | 1 | “double” | stores floating point values |
String | 2 | “string” | stores UTF8 text |
Object | 3 | “object” | stores embedded documents |
Array | 4 | “array” | can store multiple values of multiple data types |
Binary data | 5 | “binData” | stores binary data |
Undefined | 6 | “undefined” | Deprecated. Works like Null |
ObjectId | 7 | “objectId” | stores the document's ID. 12 bytes, system generated |
Boolean | 8 | “bool” | true or false |
Date | 9 | “date” | 64-bit integer representing milliseconds since 01.01.1970 |
Null | 10 | “null” | |
Regular Expression | 11 | “regex” | |
DBPointer | 12 | “dbPointer” | Deprecated. |
JavaScript | 13 | “javascript” | stores JavaScript data without Scope |
Symbol | 14 | “symbol” | Deprecated. |
JavaScript (with scope) | 15 | “javascriptWithScope” | stores JavaScript data with Scope |
32-bit integer | 16 | “int” | |
Timestamp | 17 | “timestamp” | 64-bit integer. 32 bits representing seconds since 01.01.1970 + 32 bits incrementing. Unique per Mongo instance |
64-bit integer | 18 | “long” | |
Decimal128 | 19 | “decimal” | New in version 3.4 Wikipedia:Decimal128_floating-point_format |
Min key | -1 | “minKey” | always the lowest result in a sort |
Max key | 127 | “maxKey” | always highest result in a sort |
Each data type has a number and string alias that can be used with the $type operator to query documents by BSON type. Additionally, there is a "number" alias that corresponds to all the numeric data-types.
db.addresses.find( { "areaCode" : { $type : "number" } } )
This will find all the Documents in the addresses Collection where areaCode is numeric
db.addresses.find( { "areaCode" : { $type : "string" } } )db.addresses.find( { "areaCode" : { $type : "number" } } )
This will find all the Documents in the addresses Collection where areaCode is numeric
This will find all the Documents in the addresses Collection where areaCode is text
Types can be implicitly defined:
{
screenname: "Max", // string
age: 29, // integer
visible: false, // boolean
subscriptions: ["mongoDB","MariaDB"] // array
"phone" : {"cell" : "555-123-4567",
"office" : "555-312-6789"},// Object (embedded document)
email: null // null
}
or explicitly defined:
{
"_id" : ObjectId("5b6b9f34a1f359177d123a5a"),
field1: NumberLong(123456) ,
field2: NumberInt(123456789)
}
No comments:
Post a Comment