Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有看起来像这样的键:34834.3245.94.5134 - 它显然是字符串。但我可以将其拆分并存储为整数数组 [34834,3245,94,5134]
1) 这个数组的存储、索引和搜索效率更高吗?
2) 是否可以在该键上使用 {unique:true} 创建索引?
是的,在数字足够长的情况下,您应该在内存中获得更紧凑的索引,但索引中的元素更多(它会减慢查询速度)。
是的,但请记住这条规则
如果您对复合索引使用唯一约束,那么 MongoDB 将强制值组合的唯一性,而不是键的任何或所有值的单个值。