小编SS-*_*obi的帖子

Node.js mongoose find() 方法使用对象中的键值

我想使用 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});
Run Code Online (Sandbox Code Playgroud)

我尝试的是

Newcontract.find({contractInfo: {userid: {$eq: req.body.userid}}})
Run Code Online (Sandbox Code Playgroud)

但我无法根据contractInfo对象中的这个userid获取数据

怎么做?

谢谢

mongoose mongodb node.js mongodb-schema

1
推荐指数
1
解决办法
8121
查看次数

标签 统计

mongodb ×1

mongodb-schema ×1

mongoose ×1

node.js ×1