## String 

BSON strings are UTF-8. In general, drivers for each programming language convert from the language’s string format to UTF-8 when serializing and deserializing BSON. This makes it possible to store most international characters in BSON strings with ease. 29 In addition, MongoDB $regex queries support UTF-8 in the regex string. 

## Timestamps 

BSON has a special timestamp type for internal MongoDB use and is not associated with the regular Date (page 180) type. Timestamp values are a 64 bit value where: 

• the first 32 bits are a time_t value (seconds since the Unix epoch) 

• the second 32 bits are an incrementing ordinal for operations within a given second. 

Within a single mongod instance, timestamp values are always unique. 

In replication, the oplog has a ts field. The values in this field reflect the operation time, which uses a BSON timestamp value. 

Note: The BSON timestamp type is for internal MongoDB use. For most cases, in application development, you will want to use the BSON date type. See Date (page 180) for more information. 

If you insert a document containing an empty BSON timestamp in a top-level field, the MongoDB server will replace that empty timestamp with the current timestamp value. For example, if you create an insert a document with a timestamp value, as in the following operation: 

var a = new Timestamp(); db.test.insert( { ts: a } ); 

Then, the db.test.find() operation will return a document that resembles the following: 

{ "_id" : ObjectId("542c2b97bac0595474108b48"), "ts" : Timestamp(1412180887, 1) } 

If ts were a field in an embedded document, the server would have left it as an empty timestamp value. 

Changed in version 2.6: Previously, the server would only replace empty timestamp values in the first two fields, including _id , of an inserted document. Now MongoDB will replace any top-level field. 

## Date 

BSON Date is a 64-bit integer that represents the number of milliseconds since the Unix epoch (Jan 1, 1970). This results in a representable date range of about 290 million years into the past and future. 

The official BSON specification 30 refers to the BSON Date type as the UTC datetime . 

Changed in version 2.0: BSON Date type is signed. 31 Negative values represent dates before 1970. 

## Example 

Construct a Date using the new Date() constructor in the mongo shell: 

