mongodb - 对象数组的索引参数
问题描述
我想对数组内对象的“文本”参数进行索引,因为我正在做一个搜索栏,并将查看模型的“标题”和“标签”字段
const needSchema = new Schema({
owner: {
type: ObjectId,
required: true,
ref: User
},
title: {
type: String,
required: true
},
tags: {
type: [Object],
required: false
},
}, {
timestamps: {
createdAt: 'created_at',
updatedAt: 'updated_at'
}
});
needSchema.index({ title: 'text', 'tags.text': 'text' });
const Need = mongoose.model('Need', needSchema);
实际上只有标题有效。我无法获得对象标签数组的结果。标签数组:
tag:[
{'id':'text1', 'text':'text1',
{....},
]
What is wrong?
解决方案
推荐阅读
- node.js - Node.js 中的 Require 函数
- java - 在全球范围内在 Java 中集成第三方外观
- unit-testing - 为 Mat-button [color] 的数据绑定属性编写单元测试
- flutter - Instagram 应用内浏览器破坏了 Flutter 网页
- prometheus - 我已经在 100 台不同的服务器上安装了 Node exporter,并读取了我的 prometheus 服务器上收集的数据。但无法区分数据
- python - 如何从类中产生招摇?
- json - 为什么我收到此错误错误:预期类型为“列表”的值
',但得到了 '_JsonMap' 类型之一 - c++ - C++中友元函数默认参数的私有构造函数
- sql - 条件连接大查询
- android - 您的免安装应用 APK 未声明至少一个将“android:autoVerify”属性设置为 true 的网络“intent-filter”元素