...find_one({'account.messages': 0})
...find_one({'account.messages': 1})
...find_one({'account.messages': 2})
...find_one({'account.messages': 3})
...find_one({'account.messages': 100})
...find_one({'account.messages': {'$in': [0,1,2,3,100,1000]}})
db.user.find({$or: [
{birthday: {$gte: dStart1, $lt: dEnd1}},
{birthday: {$gte: dStart2, $lt: dEnd2}},
{birthday: {$gte: dStart3, $lt: dEnd3}},
]})
db.users.aggregate(pipeline).forEach(a => {
user = db.users.findOne({_id: a._id.d_id});
for (let i = 1; i < a.count; i++) {
user.linkRole.splice(
user.linkRole.findIndex(lr => lr.role === a._id.role && lr.Organization === a._id.Organization),
1
)
}
db.users.save(user)
})
pipeline = [
{$unwind: "$linkRole"},
{$group: {
_id: {
d_id: "$_id",
role: "$linkRole.role",
Organization: "$linkRole.Organization"
},
count: {$sum: 1}
}},
{$match:{count: {$gt: 1}}}
]
db.users.aggregate(pipeline).forEach(a => {
for (let i = 1; i < a.count; i++) {
db.users.updateOne({_id: a._id.d_id}, {$pull: {linkRole: {role: a._id.role, Organization: a._id.Organization} }})
}
})
db.test.insertOne({name: null})
db.test.insertOne({name: "Alexo"})
db.test.insertOne({key: "value"})
db.test.count({name: {$exists: true}}) -> 2 {name: null}, {name: "Alexo"}
db.test.count({name: null}) -> 2 -> {name: null}, {key: "value"}
db.test.count({name: {$ne: null}}) -> 1 {name: "Alexo"}