将_Id作为对象或字符串存储在MongoDB中? [英] Store _Id as object or string in MongoDB?

查看:544
本文介绍了将_Id作为对象或字符串存储在MongoDB中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeigniter和MongoDB开发一个API。
在此系统中,我保存所选用户
所关注的用户的全名和_ID。



_ID?将它存储为对象还是字符串?
如果我将它存储为一个对象,我需要转换为字符串时回显出跟随者否则
输出看起来很奇怪。



我的问题是真的。是否可以将_Id存储为字符串而不是对象?
存储为字符串的缺点是什么?



感谢所有输入!

解决方案

请求(和更新)的性能真的更好与objectid。


p> BSON包括用于存储字节数组的二进制数据数据类型。使用
这将使id值和它们各自的键在_id
索引中的两倍小。


这里有两个可以帮助您的链接:
- http://www.mongodb。 org / display / DOCS / Optimizing + Object + IDs
- http:// www。 mongodb.org/display/DOCS/Object+IDs


I am developing an API using Codeigniter and MongoDB. In this system I am saving the full name and _ID of users that the selected user is following.

What is best to do regarding the _Id? Store it as an object or as a string? If I store it as an object I need to convert it to string when echoing out followers otherwise the output looks strange.

My question is really. Is it ok to store the _Id as a string rather than an object? What is the downside of storing as string?

Thankful for all input!

解决方案

Performance for requests (and updates) are really better with objectid. More over, objectid are quite small in space.

From the official doc :

BSON includes a binary data datatype for storing byte arrays. Using this will make the id values, and their respective keys in the _id index, twice as small.

here are 2 links that can help you : - http://www.mongodb.org/display/DOCS/Optimizing+Object+IDs - http://www.mongodb.org/display/DOCS/Object+IDs

这篇关于将_Id作为对象或字符串存储在MongoDB中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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