$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.60
List Price:  €59.64
You save:  €17.04
£36.87
List Price:  £51.62
You save:  £14.75
CA$69.16
List Price:  CA$96.83
You save:  CA$27.67
A$75.17
List Price:  A$105.25
You save:  A$30.07
S$64.12
List Price:  S$89.77
You save:  S$25.65
HK$389.03
List Price:  HK$544.68
You save:  HK$155.64
CHF 39.81
List Price:  CHF 55.75
You save:  CHF 15.93
NOK kr493.49
List Price:  NOK kr690.92
You save:  NOK kr197.43
DKK kr317.99
List Price:  DKK kr445.21
You save:  DKK kr127.22
NZ$83.95
List Price:  NZ$117.53
You save:  NZ$33.58
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,057.40
List Price:  ৳8,480.85
You save:  ৳2,423.44
₹4,412.22
List Price:  ₹6,177.47
You save:  ₹1,765.24
RM210.20
List Price:  RM294.30
You save:  RM84.10
₦75,032.99
List Price:  ₦105,052.19
You save:  ₦30,019.20
₨14,128.81
List Price:  ₨19,781.47
You save:  ₨5,652.65
฿1,584.68
List Price:  ฿2,218.68
You save:  ฿634
₺2,068.10
List Price:  ₺2,895.51
You save:  ₺827.40
B$269.45
List Price:  B$377.25
You save:  B$107.80
R867.28
List Price:  R1,214.26
You save:  R346.98
Лв83.41
List Price:  Лв116.78
You save:  Лв33.37
₩69,513.11
List Price:  ₩97,323.92
You save:  ₩27,810.80
₪166.32
List Price:  ₪232.86
You save:  ₪66.54
₱2,856.67
List Price:  ₱3,999.57
You save:  ₱1,142.89
¥7,386.09
List Price:  ¥10,341.12
You save:  ¥2,955.03
MX$923.07
List Price:  MX$1,292.38
You save:  MX$369.30
QR181.43
List Price:  QR254.01
You save:  QR72.58
P667.01
List Price:  P933.87
You save:  P266.85
KSh6,458.70
List Price:  KSh9,042.70
You save:  KSh2,584
E£2,406.99
List Price:  E£3,369.99
You save:  E£962.99
ብር7,146.86
List Price:  ብር10,006.18
You save:  ብር2,859.31
Kz45,588.63
List Price:  Kz63,827.73
You save:  Kz18,239.10
CLP$47,604.47
List Price:  CLP$66,650.07
You save:  CLP$19,045.60
CN¥355.97
List Price:  CN¥498.39
You save:  CN¥142.42
RD$3,172.31
List Price:  RD$4,441.49
You save:  RD$1,269.18
DA6,485.56
List Price:  DA9,080.30
You save:  DA2,594.74
FJ$111.93
List Price:  FJ$156.72
You save:  FJ$44.78
Q382.80
List Price:  Q535.96
You save:  Q153.15
GY$10,413.64
List Price:  GY$14,579.93
You save:  GY$4,166.29
ISK kr6,091.78
List Price:  ISK kr8,528.98
You save:  ISK kr2,437.20
DH449.44
List Price:  DH629.25
You save:  DH179.81
L830.33
List Price:  L1,162.53
You save:  L332.20
ден2,621.69
List Price:  ден3,670.58
You save:  ден1,048.88
MOP$400.93
List Price:  MOP$561.33
You save:  MOP$160.40
N$873.58
List Price:  N$1,223.08
You save:  N$349.50
C$1,831.56
List Price:  C$2,564.33
You save:  C$732.77
रु7,041.77
List Price:  रु9,859.04
You save:  रु2,817.27
S/173.20
List Price:  S/242.49
You save:  S/69.29
K210.97
List Price:  K295.38
You save:  K84.40
SAR187.54
List Price:  SAR262.58
You save:  SAR75.03
ZK1,185.88
List Price:  ZK1,660.33
You save:  ZK474.44
L216.01
List Price:  L302.44
You save:  L86.42
Kč1,035.78
List Price:  Kč1,450.17
You save:  Kč414.39
Ft16,651.48
List Price:  Ft23,313.40
You save:  Ft6,661.92
SEK kr466.18
List Price:  SEK kr652.69
You save:  SEK kr186.51
ARS$71,621.56
List Price:  ARS$100,275.91
You save:  ARS$28,654.35
Bs343.94
List Price:  Bs481.54
You save:  Bs137.60
COP$195,357.69
List Price:  COP$273,516.40
You save:  COP$78,158.71
₡25,188.10
List Price:  ₡35,265.36
You save:  ₡10,077.25
L1,303.86
List Price:  L1,825.51
You save:  L521.64
₲357,954.58
List Price:  ₲501,165.05
You save:  ₲143,210.47
$U2,002.31
List Price:  $U2,803.39
You save:  $U801.08
zł181.18
List Price:  zł253.67
You save:  zł72.48
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.