$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
€43.14
List Price:  €60.41
You save:  €17.26
£37.55
List Price:  £52.57
You save:  £15.02
CA$70.09
List Price:  CA$98.13
You save:  CA$28.04
A$77.06
List Price:  A$107.89
You save:  A$30.83
S$64.94
List Price:  S$90.93
You save:  S$25.98
HK$388.42
List Price:  HK$543.82
You save:  HK$155.40
CHF 39.83
List Price:  CHF 55.77
You save:  CHF 15.93
NOK kr502.42
List Price:  NOK kr703.43
You save:  NOK kr201
DKK kr322.28
List Price:  DKK kr451.21
You save:  DKK kr128.93
NZ$87.09
List Price:  NZ$121.93
You save:  NZ$34.84
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,106.73
List Price:  ৳8,549.92
You save:  ৳2,443.18
₹4,386.44
List Price:  ₹6,141.37
You save:  ₹1,754.93
RM211.45
List Price:  RM296.05
You save:  RM84.60
₦73,331.33
List Price:  ₦102,669.73
You save:  ₦29,338.40
₨14,160.45
List Price:  ₨19,825.77
You save:  ₨5,665.31
฿1,644.62
List Price:  ฿2,302.60
You save:  ฿657.98
₺2,098.40
List Price:  ₺2,937.92
You save:  ₺839.52
B$269.35
List Price:  B$377.11
You save:  B$107.76
R873.75
List Price:  R1,223.32
You save:  R349.57
Лв84.30
List Price:  Лв118.03
You save:  Лв33.72
₩71,574.26
List Price:  ₩100,209.69
You save:  ₩28,635.43
₪164.83
List Price:  ₪230.78
You save:  ₪65.94
₱2,922.31
List Price:  ₱4,091.47
You save:  ₱1,169.15
¥7,589.48
List Price:  ¥10,625.88
You save:  ¥3,036.40
MX$919.86
List Price:  MX$1,287.88
You save:  MX$368.02
QR182.40
List Price:  QR255.38
You save:  QR72.97
P667.54
List Price:  P934.62
You save:  P267.07
KSh6,456.20
List Price:  KSh9,039.20
You save:  KSh2,583
E£2,377.02
List Price:  E£3,328.02
You save:  E£951
ብር7,548.46
List Price:  ብር10,568.45
You save:  ብር3,019.99
Kz45,589.78
List Price:  Kz63,829.34
You save:  Kz18,239.56
CLP$47,472
List Price:  CLP$66,464.60
You save:  CLP$18,992.60
CN¥356.17
List Price:  CN¥498.67
You save:  CN¥142.50
RD$3,184.61
List Price:  RD$4,458.71
You save:  RD$1,274.10
DA6,508.94
List Price:  DA9,113.04
You save:  DA2,604.10
FJ$114.92
List Price:  FJ$160.90
You save:  FJ$45.97
Q383.31
List Price:  Q536.67
You save:  Q153.35
GY$10,470.22
List Price:  GY$14,659.15
You save:  GY$4,188.92
ISK kr6,118.77
List Price:  ISK kr8,566.77
You save:  ISK kr2,448
DH461.03
List Price:  DH645.48
You save:  DH184.45
L849.74
List Price:  L1,189.70
You save:  L339.96
ден2,658.25
List Price:  ден3,721.77
You save:  ден1,063.51
MOP$400.59
List Price:  MOP$560.87
You save:  MOP$160.27
N$866.66
List Price:  N$1,213.39
You save:  N$346.73
C$1,841.50
List Price:  C$2,578.25
You save:  C$736.74
रु7,040.48
List Price:  रु9,857.24
You save:  रु2,816.75
S/168.82
List Price:  S/236.36
You save:  S/67.54
K213.57
List Price:  K299.01
You save:  K85.44
SAR187.48
List Price:  SAR262.49
You save:  SAR75
ZK1,132.27
List Price:  ZK1,585.28
You save:  ZK453
L219.30
List Price:  L307.03
You save:  L87.73
Kč1,048.97
List Price:  Kč1,468.64
You save:  Kč419.67
Ft16,791.84
List Price:  Ft23,509.92
You save:  Ft6,718.08
SEK kr471.89
List Price:  SEK kr660.69
You save:  SEK kr188.79
ARS$72,849.44
List Price:  ARS$101,995.05
You save:  ARS$29,145.60
Bs345.80
List Price:  Bs484.15
You save:  Bs138.34
COP$194,723.13
List Price:  COP$272,627.96
You save:  COP$77,904.83
₡25,117.66
List Price:  ₡35,166.74
You save:  ₡10,049.07
L1,314.89
List Price:  L1,840.96
You save:  L526.06
₲354,504.43
List Price:  ₲496,334.57
You save:  ₲141,830.13
$U1,990.37
List Price:  $U2,786.67
You save:  $U796.30
zł182.62
List Price:  zł255.68
You save:  zł73.06
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.