【发布时间】:2016-06-03 05:47:51
【问题描述】:
文档
_id: ..
user_id (index): User1
title: Test
details (index): { gener: 'Fantasy', author: 'Author01', language: 'test', interest: 1 }
filters (index): ['black', 'red', 'green', 'medium', .... (can contain more than 40 values)]
我正在尝试索引 MongoDB 集合中的 3 个字段
user_id (holds only string as a value)
details (object of 4 key-value pairs)
filters (array which holds more than 40 values)
在 mongodb 中以这种方式索引效果好吗?如果没有,索引此类集合的更好方法是什么?
【问题讨论】:
-
索引取决于您的查询,如果您想查询单个字段或多个字段和对象,只需使用这种方式。创建单个字段索引(user_id:1)或创建多个字段与对象(user_id:1,'detail.gender':1),我的建议当数组中有更多记录时不要在数组字段中使用索引,请参阅docs.mongodb.com/manual/indexes跨度>
标签: mongodb mongodb-query database nosql