我正在使用 Codeigniter 和 MongoDB 开发一个 API。 在这个系统中,我保存了所选用户的用户的全名和 _ID 正在关注。
关于 _Id 的最佳做法是什么?将其存储为对象还是字符串? 如果我将其存储为对象,则在回显关注者时需要将其转换为字符串,否则 输出看起来很奇怪。
我的问题是真的。可以将 _Id 存储为字符串而不是对象吗? 存储为字符串的缺点是什么?
感谢所有输入!
最佳答案
使用 objectid 的请求(和更新)性能确实更好。此外,objectid 的空间非常小。
来自官方文档:
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+IDs - http://www.mongodb.org/display/DOCS/Object+IDs
关于codeigniter - 将_Id存储为MongoDB中的对象或字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7764781/