db.test.aggregate([
{
"$addFields":{
"sharesFloat": {
"$function": {
"body": "function (shares) { if (!shares) {return 0}; return parseFloat(shares.split(' ')[0])}",
"args": ["$obj.shares"],
"lang": "js"
}
}
}
},
{
"$group": {
"_id": None,
"sum": {
"$sum": "$sharesFloat"
}
}
}
])
db.collection.update_many(
{"delivery_rub": {"$lt": 0}},
[
{
"$set": {
"delivery_rub": {
"$multiply": [
"$delivery_rub",
-1
]
}
}
}
])
db.collection.aggregate([
{
"$match": {
"roommates": {
"$in": [
1
]
}
}
},
{
"$sort": {
"created_at": -1
},
},
{
"$addFields": {
"to_sum": {
"$cond": {
"if": "$viewed",
"then": 0,
"else": 1,
}
}
},
},
{
"$group": {
"_id": "$roommates",
"user": {
"$first": "$user"
},
"target": {
"$first": "$target"
},
"text": {
"$first": "$text"
},
"created_at": {
"$first": "$created_at"
},
"viewed": {
"$first": "$viewed"
},
"count": {
"$sum": "$to_sum"
}
}
},
{
"$sort": {
"created_at": -1
},
},
{
"$limit": 25
}
])
db.collection.aggregate([
{
"$match": {
"roommates": {
"$in": [
1
],
"$nin": []
}
}
},
{
"$sort": {
"created_at": -1
},
},
{
"$limit": 25
},
{
"$group": {
"_id": "$roommates",
"m": {
"$first": "$$CURRENT"
},
}
},
{
"$sort": {
"m.created_at": -1
},
},
])
cluster = AsyncIOMotorClient("")
db = cluster['Users']
collection = db['Words']
data = await collection.find().to_list(None)
for i in collection.find(query):
for i in collection.find(*query):
embed = discord.Embed(title="История наказаний", color = 0x2f3236)
async for x in nakazania.find({"member_id": member.id}):
...
let dStart = new Date();
let dEnd = new Date();
dStart.setFullYear(dStart.getFullYear() - 15);
dEnd.setFullYear(dEnd.getFullYear() - 13);
db.user.find({birthday: {$gte: dStart, $lt: dEnd}})
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 => {
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)
})