-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongodb.txt
83 lines (70 loc) · 1.89 KB
/
mongodb.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$root
$facet
$count
$limit
$lookup
pipline
$let
$expr
"$$secondUser"
$_id.name
$toDate
$inc
$$ROOT
------------------
count
groupby
limit
---
projection
-------------
Fields
The following operators can be used to update fields:
$currentDate: Sets the field value to the current date
$inc: Increments the field value
$rename: Renames the field
$set: Sets the value of a field
$unset: Removes the field from the document
Array
The following operators assist with updating arrays.
$addToSet: Adds distinct elements to an array
$pop: Removes the first or last element of an array
$pull: Removes all elements from an array that match the query
$push: Adds an element to an array
=========
{ "$match": {
"$expr": {
"$and": [
{ "$eq": ["$patientId", "$$patientId"] },
{ "$eq": ["$branchId", "$$clinic_id"] }
]
},
"acknowleged": false
}}
result = company_collection.aggregate([
{"$match": {"contacts.country": "India"}},
{"$lookup": {
"from": "users",
"localField": "_id",
"foreignField": "company_id",
"as": "users",
"pipeline": [
{ "$match": {
"$expr": {
"$and": [
{ "$gte": ["created_datetime", "2023-02-23T00:00:00+0000"] },
{ "$lte": ["created_datetime", "2023-02-23T00:00:00+0000"] }
]
}
}}, {"$project": {"email": 1}}
]
}},
{"$unwind": "$users"},
{"$project": {
'name': 1,
'email': "$users.email"
}},
{"$count": 'total_count'},
{"$project": {
'total_count': "$total_count"
}},