[英]Query in Sub document if main Document is not null
I have a schema like this我有这样的架构
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()}
}
I want to find all documents where invoice.invoice_url == null.我想找到 invoice.invoice_url == null 的所有文件。
i have used this invoice.invoice_url = null
我用过这个invoice.invoice_url = null
but it will give an error.但它会给出一个错误。 because in some cases invoice property is null.因为在某些情况下,发票属性是 null。
So I want to find from mongo only when invoice property is not null and then invoice_url is null所以我只想在发票属性不是 null 然后 invoice_url 是 null 时从 mongo 中查找
Try the below query.试试下面的查询。
db.product.find(
{"$and":[{"invoice":{"$ne":null}},
{"invoice.invoice_url":{"$eq":null}}]}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.