MongoDB 指定应用上下文数据模型

Model Data for Atomic Operations

Pattern

In mongoDB, write operations, eg. db.collection.update(), db.collection.findAndModify(), db.collection.remove(), are atomic on the level of a single document. For fields the must be updated together, embedding the fields within the same document ensures that the fields can be update atomically.

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

The available copies of the book and the checkout information should be in sync. As such, embedding the available field and checkout field within the same document ensures that the two 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 an 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 library volumes that you want to provide topic-based search. For each volume, you add the array topics, and you 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 will convert any local time representations into this form. Application 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

Storing the current date and the current offset from UTC:

Reconstruct the original local time by applying the saved offset:

时间: 2024-08-04 22:25:27

MongoDB 指定应用上下文数据模型的相关文章

Nodejs之MEAN栈开发(三)---- 使用MongoDB和Mongoose创建数据模型及API

继续开扒我们的MEAN栈开发之路,前面两节我们学习了Express.Jade引擎并创建了几个静态页面,最后通过Heroku部署了应用. Nodejs之MEAN栈开发(一)---- 路由与控制器 Nodejs之MEAN栈开发(二)----视图与模型 这一节将重点介绍MongoDB以及它的ODM(Object-Document Modeler)Mongoose.MongoDB是一种分布式文档存储型数据库,和平时使用的关系型数据库不同,它存储的是BSON格式(json的二进制),特点是高性能.易部署,

MongoDB快速上手

1.  MongoDB简介 MongoDB是一个跨平台的基于Key_Value键值对形式保存数据的NoSQL文档类型数据库. NoSQL(not only sql)数据库,泛指非关系型数据库. 1.1 NoSQL数据库的特点 l  不需要预定义模式 不需要事先定义数据模式,预定义表结构.数据中的每条记录都可能有不同的属性和格式.当插入数据时,并不需要预先定义它们的模式. l  无共享架构 相对于将所有数据存储的存储区域网络中的全共享架构.NoSQL往往将数据划分后存储在各个本地服务器上.因为从本

mongoDB (mongoose、增删改查、聚合、索引、连接、备份与恢复、监控等等)

MongoDB - 简介 官网:https://www.mongodb.com/ MongoDB 是一个基于分布式文件存储的数据库,由 C++ 语言编写,旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的. MongoDB - 安装及运行 下载 07/05/2017 Current Stable Release (3.4.6) https://www.mongodb.com/dow

MySQL与MongoDB的区别

一.MongoDB简介 什么是MongoDB ?MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统.在高负载的情况下,添加更多的节点,可以保证服务器性能.MongoDB 旨在为WEB应用提供可扩展的高性能数据存储解决方案.MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成.MongoDB 文档类似于 JSON 对象.字段值可以包含其他文档,数组及文档数组. 主要特点MongoDB的提供了一个面向文档存储,操作起来比较简单和容易.你可以在

看门外汉如何实现:C#操作 MongoDB基本CURD的事务控制

第一部分 基本设计 目前最新版本的C#驱动MongoDB-CSharpDriver-2.2.3,比之前的版本更新比较大,在网上很难找到这个版本的相关C#操作资料,以下都是个人自发研究.测试的,如有雷同,不胜荣幸:如觉不妥,留言喷射:如有错误,还请赐教:如获帮助,示意欣赏.新版中有很多异步操作,本人对此没作研究,怕会产生数据安全问题,所以全部用的是同步方法. 1. 模型设计,使用GUID类型做为Id属性,在初始化时给一个随机值,基类代码,不作解释 using System;using System

创建EF数据模型

最后的应用程序,看上去就像下边这样: 创建数据模型,你将从以下三个类开始: 在Models文件夹,新建以下类: 1 using System; 2 using System.Collections.Generic; 3 4 namespace ContosoUniversity.Models 5 { 6 public class Student 7 { 8 public int ID { get; set; } 9 public string LastName { get; set; } 10

MongoDB学习——持续更新

參考MongoDB权威指南,学习阶段.大家多多交流问题.持续更新本文 MongoDB的长处 MongoDB具有丰富的数据模型,是面向文档的数据库. easy扩展.能够在多台server之间切割数据. 开发人员仅仅需专注于编写应用.假设须要更大的数据.仅仅需在集群中加入新机器,然后让数据库来处理剩下的事情. 具有丰富的功能,比方索引,存储JavaScript,聚合,固定集合.文件存储. 不支持联接(join)和复杂的多行事物. 卓越的性能是MongoDB的主要目标,默认的存储引擎使用了内存映射文件

每天200亿次查询 – MongoDB在奇虎360【转】

100多个应用,1,500多个实例,每天200亿次查询 奇虎是中国最大的安卓移动发布平台.奇虎也是中国最顶尖的病毒软件防护公司,同时为网络以及移动平台提供产品.自从2011年成为MongoDB的用户之后,奇虎已经在MongoDB上构建了100多个不同的应用,其中包括新服务以及从MySQL和Redis上迁移过来的服务——每天都会在MongoDB上运行超过1, 500个实例并且支持200亿次查询. 我很高兴能够有一个机会与奇虎的高级DBA——杨艳杰进行交流,了解更多关于他们使用MongoDB的过程及

MongoDB下载及安装

Mongodb是时下流行的NoSql数据库,它的存储方式是文档式存储,并不是Key-Value形式. MongoDB中有三元素:数据库,集合,文档,其中“集合”就是对应关系数据库中的“表”,“文档”对应“行”. 一: 下载 上MongoDB官网 ,我们发现有32bit和64bit,这个就要看你系统了,不过这里有两点注意: ①:根据业界规则,偶数为“稳定版”(如:1.6.X,1.8.X),奇数为“开发版”(如:1.7.X,1.9.X),这两个版本的区别相信大家都知道吧. ②:32bit的mongo