ObjectId
BSON Types — MongoDB Manual https://docs.mongodb.com/manual/reference/bson-types/#objectid
ObjectId
ObjectIds are small, likely unique, fast to generate, and ordered. ObjectId values consist of 12 bytes, where the first four bytes are a timestamp that reflect the ObjectId’s creation. Specifically:
- a 4-byte value representing the seconds since the Unix epoch,
- a 5-byte random value, and
- a 3-byte counter, starting with a random value.
In MongoDB, each document stored in a collection requires a unique _id field that acts as a primary key. If an inserted document omits the _id field, the MongoDB driver automatically generates an ObjectId for the _id field.
This also applies to documents inserted through update operations with upsert: true.
MongoDB clients should add an _id field with a unique ObjectId. Using ObjectIds for the _id field provides the following additional benefits:
in the
mongoshell, you can access the creation time of theObjectId, using theObjectId.getTimestamp()method.sorting on an
_idfield that storesObjectIdvalues is roughly equivalent to sorting by creation time.IMPORTANT
While ObjectId values should increase over time, they are not necessarily monotonic. This is because they:
- Only contain one second of temporal resolution, so ObjectId values created within the same second do not have a guaranteed ordering, and
- Are generated by clients, which may have differing system clocks.
SEE ALSO
ObjectId的更多相关文章
- MongoDB数据实体中的ObjectId序列化成json的一个小坑
很多时候我们都需要对实体对象进行序列化与反序列化,而ObjectId类型,只能用mongo的驱动以bson格式来序列化,但我们对外的交互,一般是json格式. 有两种解决方案: 1.自己写一个json ...
- iOS CoreData 中 objectID 的不变性
关于 CoreData的 objectID 官方文档有这样的表述:新建的Object还没保存到持久化存储上,那么它的objectID是临时id,而保存之后,就是持久化的id,不会再变化了. 那么,我想 ...
- MongoDB学习笔记~ObjectId主键的设计
回到目录 说一些关于ObjectId的事 MongoDB确实是最像关系型数据库的NoSQL,这在它主键设计上可以体现的出来,它并没有采用自动增长主键,因为在分布式服务器之间做数据同步很麻烦,而是采用了 ...
- MongoDB的ObjectId和基本操作增删改查(3)
ObjectId 基本操作增删改查 增: insert 介绍: mongodb存储的是文档,. 文档是json格式的对象. 语法: db.collectionName.insert(document) ...
- spring mvc fastJson 自定义类型转换(返回数据) 实现对ObjectId类型转换
json用的alibaba fastJson ValueFilter filter = new ValueFilter() { @Override public Object process(Obje ...
- ios coredata NSManagedObject 的 objectID
要使用这个属性一定要注意先把数据保存下,不然会变化的!就无法通过 - (NSManagedObject*)existingObjectWithID:(NSManagedObjectID*)object ...
- ObjectID和Handle
一个dwg对应一个arx database,也就是一套9个符号表和一个有名词典. 一个CAD session中是可以加载多个database的.加载后每个对象都有一个handle和一个objectid ...
- java 查询 mongodb 中的objectid
网上找了很久查询objectid的方法都是错的,用mongovue能查询出来,但就是用java不知道怎么查询 1.mongovue里的查询方式: {"_id" : ObjectId ...
- mongo里面根据对象字段的ID查询 db.Photo.find({'owner.$id':ObjectId('xxxx')}) , 并且使用forEach循环修改查询的数据
var ones = db.Photo.find({'owner.$id':ObjectId("5344f0dab7c58e8e098b4567")}) db.Photo.find ...
- MongoDB ObjectId
概述 > db.col.find() { , } { , } { , } { , } 每个文档中都有一个“_id”,她是一个12字节的BSON类型数据,格式如下 56c56dd4ca446fab ...
随机推荐
- Linux系统(Ubuntu/Debian/RedHat/CentOS)超级简单的samba配置文件smb.conf
1.超简单的smb.conf 该配置文件对Ubuntu和CentOS都好用. #============== Global Settings ============== [global] ## Br ...
- Mac环境配置好ant后提示Permission denied
1.ant环境变量配置如下 打开终端,输入vi ~/.bash_profile export ANT_HOME=/Users/administrator/Documents/software/apac ...
- js 树菜单 ztree
http://www.ztree.me/v3/api.php 官网 api js /** <div id="menuContent" class="menuCont ...
- win7下如何显示缅文和使用缅文输入法?
windows 7 操作系统默认不支持缅文,所以缅文在win7上不能显示,当然也没有提供缅文输入法. 一.显示缅文 windows系统下显示缅文字母只需要安装缅文字体就可以了.目前常见的缅文字体就是Z ...
- C++-教程2-VS2010C++相关文件说明
stdafx.h说明:stdafx的英文全称为:Standard Application Framework Extensions(标准应用程序框架的扩展).所谓头文件预编译,就是把一个工程(Proj ...
- Odoo 8.0 new API 之constrains装饰
constrains装饰用于对字段进行限制 应用举例: 定义列: age = fields.Integer(string="age") 方法: @api.constrains('a ...
- oozie中时间EL表达式
EL表达式: 常量表示形式 含义说明 ${coord:minutes(int n)} 返回日期时间:从一开始,周期执行n分钟 ${coord:hours(int n)} 返回日期时间:从一开始,周期执 ...
- WCF服务三:svc文件详解
在前面的文章中讲述过WCF服务的宿主程序主要包括:三种,在那篇文章中,简单的描述了如何把一个WCF服务寄宿到IIS上面,这篇文章中将具体讲述如何把一个WCF服务寄宿到IIS上面. 一.新建一个WCF服 ...
- C++ 运算符重载三(链式编程)
//运算符重载之链式编程 #include<iostream> using namespace std; //对于友元函数重载运算符只适用于左操作数是系统变量的场景 //因为成员无法在系统 ...
- MyBatis-Spring 使用总结
说明:Java-based Config. 不是通过 mybatis 的 SqlSessionFactoryBuilder 来创建 SqlSessionFactory ,而是通过 mybatis-sp ...