CNode

mongodb 文本索引

问答
JJustforNode发布于9 年前最后回复9 年前4 回复3856 浏览0 收藏

const FeedbackSchema = new Schema({ content: String, user: { mobile: String, real_name: String, description: String, } }) 例如有个这样的schema,user字段是一个对象,如何给user字段的description添加文本索引?

查看回复

回复 (4)

J
JustforNode#1·9 年前

会了,FeedbackSchema.index({ 'user. description': 'text' });

B
beyond5959#2·9 年前
const FeedbackSchema = new Schema({
content: String,
user: {
mobile: String,
real_name: String,
description: {
	type: String,
	index: true,
},
}
})

这样?

J
JustforNode#3·9 年前
引用 beyond5959这样?

@beyond5959 这样加的貌似不是文本索引,是单键索引

F
fengyinchao#4·9 年前

mark

参与回复
登录后即可参与回复。登录