diff options
author | Boris Verkhovskiy <boris.verk@gmail.com> | 2024-04-03 04:31:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 04:31:13 -0700 |
commit | fbf132752b743d0f43c3395da0699bee53da22df (patch) | |
tree | 56da43c86e1aebd24e3913b405e21d6f2812e9a3 /mongodb.html.markdown | |
parent | 247dc6e86c1421fa031e4b61c42c05ca6e09bfb0 (diff) | |
parent | c166f2acb295627c5ae305a6dd517a27ca8fece6 (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. |