【问题标题】:How to use filter query correctly如何正确使用过滤查询
【发布时间】:2020-08-29 04:21:54
【问题描述】:

我有这个猫鼬模式

const AddressSchema = new Schema({
    city : String,
    address : String,
    favorite : Boolean,
    description:String,
    lat : String,
    lng : String,
});

export const orderSchema = new Schema({
  id: {
    type: Number,
    require: [true, "EL id es necesario"],
    default: 0
  },
  newAddress : AddressSchema,
});

我正在尝试使用 newAddress 对象中的 city 参数搜索记录,类似这样的

//ordersModel its the same Order Schema
const ActiveOrders = await this.ordersModel.find({newAddress:{city : city}});

但我得到了这个错误

(property) newAddress?: Condition<Address>
No overload matches this call.
  The last overload gave the following error.
    Type '{ city: string; }' is not assignable to type 'Condition<Address>'.
      Type '{ city: string; }' is missing the following properties from type 'Address': address, favorite, description, lat, lng

【问题讨论】:

    标签: node.js mongodb mongoose nestjs


    【解决方案1】:

    我不完全知道您为什么会收到错误消息,但如果您想按城市查找订单,您应该如下所述更改您的查询。

    const ActiveOrders = await User.find({"newAddress.city" : city});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多