【发布时间】:2018-12-16 01:10:18
【问题描述】:
我从 mongodb 文档中知道,我们只能将字符串或字符串数组设置为文本索引以供将来搜索。我想知道是否可以将作为对象的字符串属性的字符串作为索引。例如:
Person: {
name: String
}
可以命名为文本索引吗?
【问题讨论】:
标签: mongodb mongoose mongodb-query mongoose-schema
我从 mongodb 文档中知道,我们只能将字符串或字符串数组设置为文本索引以供将来搜索。我想知道是否可以将作为对象的字符串属性的字符串作为索引。例如:
Person: {
name: String
}
可以命名为文本索引吗?
【问题讨论】:
标签: mongodb mongoose mongodb-query mongoose-schema
是的,你绝对可以:
db.collection.createIndex({'Person.name': 'text'});
在猫鼬中:
schema.index({'Person.name': 'text'});
【讨论】:
overview: {type: {blocks: [{ key: String, data: {}, text: String}]}},我想通过“块”内的文本字段进行搜索。问题是我有一个对象数组,我想在数组的每个对象的每个“文本”字段中进行搜索。
db.collection.createIndex({'overview.type.blocks.text': 'text'}) 并没有结果
$text 运算符:db.collection.find({$text: {$search: 'search this text'}})。