## Model Time Data 

## Overview 

MongoDB stores times in UTC (page 180) by default, and will convert any local time representations into this form. Applications that must operate or report on some unmodified local time value may store the time zone alongside the UTC timestamp, and compute the original local time in their application logic. 

## Example 

In the MongoDB shell, you can store both the current date and the current client’s offset from UTC. 

var now = new Date(); db.data.save( { date: now, offset: now.getTimezoneOffset() } ); 

You can reconstruct the original local time by applying the saved offset: 

var record = db.data.findOne(); var localNow = new Date( record.date.getTime() - ( record.offset * 60000 ) ); 

## 4.4 Data Model Reference 

Documents (page 168) MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs. 

Database References (page 171) Discusses manual references and DBRefs, which MongoDB can use to represent relationships between documents. 

GridFS Reference (page 174) Convention for storing large files in a MongoDB Database. 

ObjectId (page 176) A 12-byte BSON type that MongoDB uses as the default value for its documents’ _id field if the _id field is not specified. 

BSON Types (page 178) Outlines the unique BSON types used by MongoDB. See BSONspec.org 12 for the complete BSON specification. 

## 4.4.1 Documents 

MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs: 

{ "item": "pencil", "qty": 500, "type": "no.2" } 

Most user-accessible data structures in MongoDB are documents, including: 

• All database records. 

• Query selectors (page 60), which define what records to select for read, update, and delete operations. 

• Update definitions (page 73), which define what fields to modify during an update. 

• Index specifications (page 486), which define what fields to index. 

• Data output by MongoDB for reporting and configuration, such as the output of the serverStatus and the replica set configuration document (page 652). 

