MongoDB的规范和POCO [英] Mongodb NoRM and POCO

查看:938
本文介绍了MongoDB的规范和POCO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中使用的MongoDB和规范进行试验。

I am experimenting with Mongodb and NoRM in C#.

这是我看过的唯一标识在MongoDB中的文档是一种特殊的Guid的的ObjectId (在这个意义上是独一无二的),但在它的一些显著份允许更容易的排序和索引(时间戳机散列,进程ID和在其增量)。

From what I have read the ObjectId that uniquely identifies a document in Mongodb is a sort of "special" Guid (in the sense that is unique) but has some significant parts in it that permit a more easy sorting and indexing (timestamp,machine hash,processId and increment in it).

我想保持我的对象真的POCO与自动生成的GUID作为ID,以便在没有外部类型如的ObjectId会阻止我迁移到另一种技术或返回到经典Ado.net或NHibernate的东西。

I'd like to keep my objects really POCO with an autogenerated Guid as Id so with no external types like ObjectId that would prevent me to migrate to another technology or go back to classic Ado.net or Nhibernate stuff.

另一种选择是在POCO的标识使用的字符串,并使用 ObjectId.NewObjectId()的ToString()

Another option would be to use in the POCO an Id as string and use ObjectId.NewObjectId().ToString()

什么是它的最佳实践?

推荐答案

的ObjectId都没有的GUID。 GUID是MS给出UUID的版本,他们使用的名称。的ObjectID是一个完全不同的算法。

ObjectId are not guids. Guid is the name that MS gives for the version of UUID that they use. ObjectIds are a completely different algorithm.

话虽这么说,不管你喜欢在蒙戈一个ID就可以使用,而且不会有性能损失(在轨世界上几个奥姆斯的提倡用字符串)

That being said, you can use whatever you like as an ID in mongo, and it won't have performance penalties (in the rails world, a few of the ORMs advocate using strings)

ObjectId存在于蒙戈大多采用节省尺寸。如果这是一个大问题,只是用别的东西,只是意识到,使用不必要的大的ID字段将最终只是浪费内存。但是,如果它是一个大问题,然后去的GUID。

ObjectId is used in mongo mostly to save size. If it is that big a deal, just use something else, just realize that using needlessly large ID fields will end up just wasting ram. But if it is a big deal, then go for Guids.

这篇关于MongoDB的规范和POCO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆