MongoDB Basics: Chapter 4: Advanced CRUD Operations - Expressive Query Operator


No Action
1
MongoDB Basics: Chapter 4: Advanced CRUD Operations - Expressive Query Operator

0 comment

21 December 2020, 8:12 am by antelove19

MongoDB Basics: Chapter 4: Advanced CRUD Operations - Expressive Query Operator
MongoDB Basics: Chapter 4: Advanced CRUD Operations - Expressive Query Operator

This lesson used the following commands: Connect to the Atlas cluster: ```javascript mongo "mongodb+srv://:@.mongodb.net/admin" ```
Switch to this database: ```javascript use sample_training ```
Find all documents where the trip started and ended at the same station: ```javascript db.trips.find({ "$expr": { "$eq": [ "$end station id", "$start station id"] } }).count() ```
Find all documents where the trip lasted longer than 1200 seconds, and started and ended at the same station: ```javascript db.trips.find({ "$expr": { "$and": [ { "$gt": [ "$tripduration", 1200 ]}, { "$eq": [ "$end station id", "$start station id" ]} ]}}).count() ```

Keywords:



Sources:

  1. university.mongodb.com