【问题标题】:MongoDB indexing multiple fieldsMongoDB索引多个字段
【发布时间】: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


【解决方案1】:

$text 对使用文本索引索引的字段的内容执行文本搜索。 示例:

  db.collection.createIndex( { "$**": "text" } )

reference here

【讨论】:

    猜你喜欢
    • 2020-10-11
    • 2016-01-18
    • 2012-11-16
    • 2016-10-24
    • 1970-01-01
    • 2014-02-24
    • 1970-01-01
    • 2020-07-20
    • 2011-08-28
    相关资源
    最近更新 更多