$where operator

2 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€42.93
List Price:  €60.10
You save:  €17.17
£37.46
List Price:  £52.44
You save:  £14.98
CA$69.12
List Price:  CA$96.78
You save:  CA$27.65
A$75.26
List Price:  A$105.37
You save:  A$30.11
S$64.76
List Price:  S$90.67
You save:  S$25.91
HK$389.16
List Price:  HK$544.86
You save:  HK$155.69
CHF 40.18
List Price:  CHF 56.26
You save:  CHF 16.07
NOK kr505.23
List Price:  NOK kr707.37
You save:  NOK kr202.13
DKK kr320.68
List Price:  DKK kr448.97
You save:  DKK kr128.29
NZ$86.53
List Price:  NZ$121.15
You save:  NZ$34.62
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,116.06
List Price:  ৳8,562.98
You save:  ৳2,446.91
₹4,497.02
List Price:  ₹6,296.19
You save:  ₹1,799.17
RM205.50
List Price:  RM287.72
You save:  RM82.22
₦72,526.70
List Price:  ₦101,543.19
You save:  ₦29,016.48
₨14,014.55
List Price:  ₨19,621.49
You save:  ₨5,606.94
฿1,592.73
List Price:  ฿2,229.95
You save:  ฿637.22
₺2,125.87
List Price:  ₺2,976.39
You save:  ₺850.52
B$271.91
List Price:  B$380.70
You save:  B$108.78
R846.14
List Price:  R1,184.67
You save:  R338.52
Лв83.98
List Price:  Лв117.58
You save:  Лв33.60
₩73,675.26
List Price:  ₩103,151.26
You save:  ₩29,476
₪161.74
List Price:  ₪226.45
You save:  ₪64.71
₱2,947.66
List Price:  ₱4,126.96
You save:  ₱1,179.30
¥7,766.44
List Price:  ¥10,873.64
You save:  ¥3,107.20
MX$908.54
List Price:  MX$1,272.04
You save:  MX$363.49
QR182.21
List Price:  QR255.11
You save:  QR72.89
P664.14
List Price:  P929.85
You save:  P265.71
KSh6,466.31
List Price:  KSh9,053.35
You save:  KSh2,587.04
E£2,373.62
List Price:  E£3,323.27
You save:  E£949.64
ብር7,753.82
List Price:  ብር10,855.98
You save:  ብር3,102.15
Kz45,840.83
List Price:  Kz64,180.83
You save:  Kz18,340
CLP$46,084.78
List Price:  CLP$64,522.38
You save:  CLP$18,437.60
CN¥353.43
List Price:  CN¥494.83
You save:  CN¥141.40
RD$3,201.94
List Price:  RD$4,482.97
You save:  RD$1,281.03
DA6,487.24
List Price:  DA9,082.66
You save:  DA2,595.41
FJ$112.99
List Price:  FJ$158.20
You save:  FJ$45.20
Q382.91
List Price:  Q536.11
You save:  Q153.19
GY$10,458.56
List Price:  GY$14,642.82
You save:  GY$4,184.26
ISK kr6,395.49
List Price:  ISK kr8,954.20
You save:  ISK kr2,558.70
DH461.70
List Price:  DH646.42
You save:  DH184.71
L850.55
List Price:  L1,190.84
You save:  L340.29
ден2,645.65
List Price:  ден3,704.12
You save:  ден1,058.47
MOP$400.86
List Price:  MOP$561.24
You save:  MOP$160.37
N$847.22
List Price:  N$1,186.17
You save:  N$338.95
C$1,839.66
List Price:  C$2,575.68
You save:  C$736.01
रु7,191.23
List Price:  रु10,068.30
You save:  रु2,877.06
S/168.03
List Price:  S/235.26
You save:  S/67.22
K212.12
List Price:  K296.99
You save:  K84.86
SAR187.61
List Price:  SAR262.67
You save:  SAR75.05
ZK1,155.73
List Price:  ZK1,618.12
You save:  ZK462.38
L218.58
List Price:  L306.03
You save:  L87.45
Kč1,038.96
List Price:  Kč1,454.63
You save:  Kč415.67
Ft16,243.25
List Price:  Ft22,741.85
You save:  Ft6,498.60
SEK kr469.93
List Price:  SEK kr657.94
You save:  SEK kr188.01
ARS$71,553.30
List Price:  ARS$100,180.35
You save:  ARS$28,627.04
Bs345.44
List Price:  Bs483.64
You save:  Bs138.20
COP$189,920.36
List Price:  COP$265,903.70
You save:  COP$75,983.34
₡24,418.74
List Price:  ₡34,188.19
You save:  ₡9,769.45
L1,316.61
List Price:  L1,843.36
You save:  L526.75
₲343,808.75
List Price:  ₲481,359.76
You save:  ₲137,551.01
$U1,953.05
List Price:  $U2,734.43
You save:  $U781.37
zł181.59
List Price:  zł254.25
You save:  zł72.65
Already have an account? Log In

Transcript

There is also a simple mechanism to work with conditions. This can be done with the help of $1 where operator which takes a string, representing a condition. However, these conditions would operate on the properties using the JavaScript notation. Let's take an example. dB dot sales dot find dollar where and a string. And here, the properties must be accessed with the help of this keyword with this represents the current object or current document being processed.

So what MongoDB does is MongoDB going to take every document in the sales collection one by one, and checks this condition. Is it true for the current document? And if that is true for the current document that is prepared for the output? If not, it's ignored. So if I do hear this start quarter equals two equals to one, notice that double equals because this is JavaScript, and then I can say R. And I can say this dot quarter equals to equals to three. This has the exact same condition as in the dollar or operator where we said quarter equals to one quarter equals to three.

So let's give it a try and say how many documents match this condition. So I'm going to go type here, Mongo, e x 09 dot j s, and it's coming back with 138. So if I go and change this to save, for example, for now, I should see a different result. We can also say something like this dot sales underscore amount greater than or equals to 5000. And this dot sales underscore amount less than or equal to 6000. So this is a very simple mechanism to execute a query.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.