Meteor.Collection.ObjectID()与MongoDB ObjectId() [英] Meteor.Collection.ObjectID() vs MongoDB ObjectId()
问题描述
为什么Meteor.js使用它自己的ID算法?
Why does Meteor.js use it's own algorithms for IDs?
为什么不使用MongoDB的ObjectId()?
Why doesn't it use MongoDB's ObjectId()?
推荐答案
如果选择使用流星,则对对象ID使用相同的方法:
Meteor uses the same method for object id's if you choose to use it:
Meteor.Collection.ObjectID()
与MongoDB的ObjectID
Meteor.Collection.ObjectID()
is the same as MongoDB's ObjectID
它在Meteor.Collection
名称下.它使用EJSON将普通JSON中的对象ID保留到客户端.因为基本上有2个带有流星的数据库
Its just under the Meteor.Collection
name. It uses EJSON to hold object id's in ordinary JSON to the client end. Because basically there are 2 databases with meteor
Minimongo
这是客户端上mongodb的一种缓存.加载浏览器后,数据将从服务器上的主mongodb下载到该数据库.进行更改后,它们将被推送到服务器.
This is a sort of cache of mongodb on the client end. The data is downloaded from the main mongodb on the server to this one when the browser loads up. When changes are made they are pushed up to the server.
服务器MongoDB
这是服务器上10gen的原始mongodb
This is the original mongodb from 10gen on the server
因此,由于这两个数据库,Meteor需要将mongodb功能包装在Meteor.Collection
中,并允许您在客户端和服务器上使用相同的代码.
So because of these two databases Meteor needs to wrap mongodb functionality in Meteor.Collection
and let you use the same code on both the client and server.
默认情况下,流星不会使用对象ID,它将使用某种随机的字母数字文本.这样做是为了方便您在URL和HTML属性中轻松使用ID.
By default meteor won't use Object IDs it'll use sort of random alphanumeric text. This is done so you can easily use ID's in your URL's and ID's in your html attributes.
如果确实使用new Meteor.Collection.ObjectID()
,则将获得一个ObjectID
对象,该对象将在服务器端使用mongodb的ObjectID规范.对象ID中的时间戳值没有保留,但这实际上并没有什么害处.
If you do use new Meteor.Collection.ObjectID()
you will get an ObjectID
object that will use mongodb's specification of ObjectID on the server end. The timestamp value in the Object ID isn't held up but this shouldn't really do any harm.
这篇关于Meteor.Collection.ObjectID()与MongoDB ObjectId()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!