MongoDB Specifies the application context data model

Source: Internet
Author: User
Tags local time utc time stamp

Model Data for Atomic Operations Pattern

In MongoDB, write operations, eg. Db.collection.update (), Db.collection.findAndModify (), Db.collection.remove (), is atomic on the level of a single docume Nt. For fields The must is updated together, embedding the fields within the same document ensures that the fields can be UPDA Te atomically.

For example, consider the situation where you need to maintain the book information, including the number of copies Availa BLE for checkout as well as the checkout information.

The available copies of the book and the checkout information should is in sync. As such, embedding the available field and checkout field within the same document ensures that the Field atomically.

Then-to-Update with new checkout information, you can use the Db.collection.update () method to atomically update both the available field and the checkout field.

Model Data to support Keyword Search

This pattern describes one method for supporting keyword search using MongoDB to support application search functionality, That use keywords stored in a array in the same document as the text field. Combined with a Multi-key index, this pattern can support application ' s keyword search operations.

Given A collection of the library volumes that's want to provide topic-based search. For each volume, you add the array topics, and your add as many keywords as needed for a given volume.

For the Moby-dick Volume:

You then can create a Multi-key index on the topics array:

The Multi-key index create separate index entry for each keyword in the topic array. For example, the index contain one entry for whaling and another for allegory:

Model Monetary Data

......

Model Time Data Overview

MongoDB stores time in UTC by default, and would convert any local time representations to this form. Application that must operate or report on some unmodified local time value may store the time zone alongside the UTC time Stamp, and compute the original local time in their application logic.

Example

Storing the current date and the current offset from UTC:

Reconstruct the original local time by applying the saved offset:

MongoDB Specifies the application context data model

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.