I prepare query with match condition, and use $nin
. I need select all document where status not equal 0,5,50,1
. Maybe I'am not correct understand $nin
operator. $nin
- the field value is not in the specified array or. It's means not equal 5, or not equal 50, but value 5 not equal 50 and this documant satisfies.... But it's not make sense. Which operator implement strong condition - not equal elements from array (like and)
This is my query
db.getCollection('inv').aggregate(
[
{ $match: { $and: [ { status: {$nin: [0, 5, 50, 1]}} ] } },
{ $sort: { increment_id: -1 } },
{ $limit: 5 },
{
$project:
{
status: 1,
item: 1,
entity_id: 1,
increment_id: 1,
due_date: 1,
current_date: new Date(),
type_code: 1,
compare_duo_date:
{
$cond: { if: { $lt: [
{ $dateFromString: {
dateString: {$dateToString: { format: "%Y-%m-%d", date: "$due_date" }} } },
{ $dateFromString: {
dateString: {$dateToString: { format: "%Y-%m-%d", date: new Date() }} } }
] }, then: 1, else: 0 }
}
}
}
]
)