node.js - 枚举数组文本不使用 $text 搜索
问题描述
我的架构是
const mongoose = require('mongoose');
const ProductSchema = new mongoose.Schema({
title: {
type: String,
required: true,
trim: true,
text: true
},
price: {
type: Number,
required: true,
trim: true
},
description: {
type: String,
required: true,
trim: true,
text: true
},
productImages: [
{
type: String,
required: true,
trim: true
}
],
availability: {
type: Boolean,
required: true,
trim: true
},
category: {
type: String,
required: true,
enum: ["mobile","computer","televisions","shoes","headphone","bag","camera","cloth","sports","books"],
text: true
}
});
mongoose.model('product', ProductSchema);
我的代码是
exports.ProductSearch = (req,res) => {
const { data } = req.body;
const query = { $text: { $search: data } };
Product.find(query)
.then(res=>{
console.log(`FIND RESPONSE 1 - `, res);
})
.catch(err=>{
console.log(`FIND ERROR - `, err)
});
}
解决方案
推荐阅读
- r - 在 ROC 曲线上添加 pch 并标记 AUC 值
- .net - 无法理解 .net 中同步上下文的目的
- angular - Angular Material Date Picker - 根据外部 API 调用禁用日期
- kotlin - 致命异常:主要:okhttp3.RealCall.execute
- c++ - 为什么单行注释中的换页和垂直制表符的处理方式不同?
- javascript - 通过 jquery 获取和设置图片 URL
- android - FAB的颜色什么时候依赖colorAccent?
- swift - iOS Swift WebRTC - 无法设置远程报价 sdp:无法设置远程视频描述发送参数
- python-3.x - tktable模块安装问题。_tkinter.TclError:无效的命令名称“表”
- java - 从 Java 中的多模块项目生成数据流模板