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

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

问题描述

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

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.

关于 _Id 的最佳做法是什么?将其存储为对象还是字符串?如果我将它存储为一个对象,我需要在回显关注者时将其转换为字符串,否则输出看起来很奇怪.

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.

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

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?

感谢所有输入!

推荐答案

使用 objectid 时请求(和更新)的性能确实更好.而且,objectid 在空间上非常小.

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

来自官方文档:

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

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.

这里有 2 个链接可以帮助您:- http://www.mongodb.org/display/DOCS/Optimizing+Object+身份证- http://www.mongodb.org/display/DOCS/Object+IDs

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天全站免登陆