$
in mongoDB is used for various different purposes
$eq
- Equal To operator$ne
- Not Equal To operator$gt
/ $gte
- Greater than or Greater than equal to$lt
/ $lte
- Less than or Less than Equal tosame syntax as before, i.e. -
{ <field> : { <operator> : <value> } }
For example, let's say from the sample_training.trips
dataset, we need to find all the users that travelled for less than or equal to 70 seconds and not a subscriber. The query for the same would be
db.trips.find({"trip duration" : {"$lte": 70} }, "usertype": { "$ne": "subscriber"})
$and
$or
$nor
$not
$not
all the other operators has the same syntaxdb.collection_name.find(<operator>: [{condition1}, {condition2}...]
$not
db.collection_name.find("$not": {condition})
For example, let's say we want all the documents in the inspections collection that does not have the result category of Pass, Fail, Violation Issued and No Violation Issued