繁体   English   中英

如果主文档不是null,则在子文档中查询

[英]Query in Sub document if main Document is not null

我有这样的架构

product: {
    _id: mongoose.Schema.Types.ObjectId,
    client_name: { type: String, required: [true, "Client Name is Required"]},
    invoice: {
        type:{
            professional_fee: { type: Number, required: [true, "Professional Fee is Required"]},
            approved_expense: { type: Number, default: 0},
            document_expense: { type: Number, default: 0},
            other_expense: { type: Number, default: 0},
            invoice_url: {type: String, default: null},
            created_on: {type: Date, default: Date.now()},
            modified_on: {type: Date, default: Date.now()}
        },
        default: null
    },
    created_on: {type: Date, default: Date.now()},
    modified_on: {type: Date, default: Date.now()}
}

我想找到 invoice.invoice_url == null 的所有文件。

我用过这个invoice.invoice_url = null

但它会给出一个错误。 因为在某些情况下,发票属性是 null。

所以我只想在发票属性不是 null 然后 invoice_url 是 null 时从 mongo 中查找

试试下面的查询。

db.product.find(
    {"$and":[{"invoice":{"$ne":null}},
    {"invoice.invoice_url":{"$eq":null}}]}
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM