【发布时间】:2021-06-30 14:44:02
【问题描述】:
我正在下面我的模型中的location 对象上对我的 API 设置 mongo db 测试搜索。
尝试在数据库中设置文本搜索时出现错误,如下所示。请问可能是什么问题?
const mongoose = require('mongoose')
const placeSchema = new mongoose.Schema({
owner: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User'
},
location: {
country: {
type: String,
required: true,
},
street: {
type: String,
required: true,
},
city: {
type: String,
required: true,
},
state: {
type: String,
required: true,
},
zip: {
type: String,
required: true,
}
},
price: {
currency: {
type: String,
required: true
},
amount: {
type: Number,
required: true
}
}
img: {
type: Boolean,
required: false,
default: false
},
phone: {
code: {
type: String,
required: true
},
number: {
type: String,
required: true,
}
},
})
placeSchema.index({ location.country: 'text', location.street: 'text', location.city: 'text', location.state: 'text', location.zip: 'text' })
const Place = mongoose.model('Place', placeSchema)
module.exports = Place
【问题讨论】:
标签: javascript node.js mongodb mongoose mongodb-atlas