diff options
author | Boris Verkhovskiy <boris.verk@gmail.com> | 2024-04-03 02:30:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 02:30:27 -0700 |
commit | 6d87022050ffbd5d818781427329c5362e3df197 (patch) | |
tree | 3809b2b1a7790d8b30e6d694c575eb68f02f661c /mongodb.html.markdown | |
parent | c76b8f690a577d9ff89947d79c36a96a7c3b4deb (diff) | |
parent | e8dabf3c1955e1a458e8bc936587ad59772a9c33 (diff) |
Merge branch 'master' into patch-1
Diffstat (limited to 'mongodb.html.markdown')
-rw-r--r-- | mongodb.html.markdown | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/mongodb.html.markdown b/mongodb.html.markdown index 959b57d0..f4e7d709 100644 --- a/mongodb.html.markdown +++ b/mongodb.html.markdown @@ -228,7 +228,7 @@ db.engineers.update({ name: 'Foo Baz' }, ) /////////////////////// Delete ///////////////////////// -// Queries are in the form of db.collectionName.find(<filter>) +// Queries are in the form of db.collectionName.delete(<filter>) // Delete first document matching query, always returns deletedCount db.engineers.deleteOne({ name: 'Foo Baz' }) @@ -252,20 +252,21 @@ db.engineers.deleteMany({ gender: 'Male' }) //////////////// Comparison Operators /////////////////// // Find all greater than or greater than equal to some condition -db.engineers.find({ $gt: { age: 25 }}) -db.engineers.find({ $gte: { age: 25 }}) +db.engineers.find({ age: { $gt: 25 }}) +db.engineers.find({ age: { $gte: 25 }}) // Find all less than or less than equal to some condition -db.engineers.find({ $lte: { age: 25 }}) -db.engineers.find({ $lte: { age: 25 }}) +db.engineers.find({ age: { $lt: 25 }}) +db.engineers.find({ age: { $lte: 25 }}) // Find all equal or not equal to // Note: the $eq operator is added implicitly in most queries -db.engineers.find({ $eq: { age: 25 }}) -db.engineers.find({ $ne: { age: 25 }}) +db.engineers.find({ age: { $eq: 25 }}) +db.engineers.find({ age: { $ne: 25 }}) -// Find all that match any element in the array -db.engineers.find({ age: ${ in: [ 20, 23, 24, 25 ]}}) +// Find all that match any element in the array, or not in the array +db.engineers.find({ age: { $in: [ 20, 23, 24, 25 ]}}) +db.engineers.find({ age: { $nin: [ 20, 23, 24, 25 ]}}) //////////////// Logical Operators /////////////////// @@ -293,7 +294,7 @@ db.engineers.find({ $not: { // Must match none of the query conditions db.engineers.find({ $nor [ - gender: 'Female, + gender: 'Female', age: { $gte: 18 } @@ -400,6 +401,6 @@ features, I would look at - Aggregation - useful for creating advanced queries to be executed by the database -- Idexing allows for caching, which allows for much faster execution of queries +- Indexing allows for caching, which allows for much faster execution of queries - Sharding allows for horizontal data scaling and distribution between multiple machines. |