我想使用 find() 函数从 mongodb 中查找数据这是我的架构
const newcontractSchema = mongoose.Schema({
creator: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: false,
index: true,
},
status: {type: String, required: false, default: 'init'},
a_status: {type: String, required: false, default: 'pending'},
contractInfo: {
startDate: {type: Date},
endDate: {type: Date},
expectedUsage: {type: Number, default: 2000},
provider: {type: Object},
rate: {type: Number},
term: {type: Number},
userid: {type: String}
}, {timestamps: true});
我尝试的是
Newcontract.find({contractInfo: {userid: {$eq: req.body.userid}}})
但是我无法根据 contractInfo 对象中的这个用户 ID 获取数据
怎么做?
谢谢