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()?
推荐答案
Meteor 对对象 id 使用相同的方法,如果您选择使用它:
Meteor uses the same method for object id's if you choose to use it:
Meteor.Collection.ObjectID()
与MongoDB的ObjectID
它就在 Meteor.Collection
名称之下.它使用 EJSON 将普通 JSON 中的对象 ID 保存到客户端.因为基本上有2个带有meteor的数据库
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.
默认情况下,meteor 不会使用对象 ID,它会使用某种随机的字母数字文本.这样做是为了让您可以轻松地在 URL 中使用 ID,在 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屋!