> ## Documentation Index
> Fetch the complete documentation index at: https://docs.synehq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB Shell (mongosh)

> Execute native MongoDB queries and aggregation pipelines with mongosh syntax

Execute native MongoDB queries and aggregation pipelines directly using mongosh syntax. SyneHQ provides full support for MongoDB's native query language, allowing you to leverage the complete power of MongoDB operations.

<Frame>
  <img src="https://2839184068-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh3pxl4sSLyris6mbVyHW%2Fuploads%2F8w5jkVqUNAAL2eJVavYh%2Fimage.png?alt=media&token=6731c0b6-d6f2-466c-b859-da1a31772627" alt="MongoDB Shell Interface" />
</Frame>

## Why Use Mongosh?

<CardGroup cols={2}>
  <Card title="Native MongoDB Syntax" icon="code">
    Use MongoDB's native query language without any abstraction layers
  </Card>

  <Card title="Full Feature Support" icon="check-circle">
    Access all MongoDB operations including aggregation pipelines and complex queries
  </Card>

  <Card title="Performance Optimized" icon="bolt">
    Direct execution against MongoDB with no translation overhead
  </Card>

  <Card title="Familiar Environment" icon="terminal">
    Standard mongosh syntax that MongoDB developers already know
  </Card>
</CardGroup>

## [Aggregation Pipeline](https://www.mongodb.com/docs/manual/core/aggregation-pipeline/#aggregation-pipeline)

This section shows aggregation pipeline examples that use the following pizza orders collection:

### Complete Aggregation Pipeline Example

```bash theme={"system"}
db.orders.insertMany( [
   { _id: 0, name: "Pepperoni", size: "small", price: 19,
     quantity: 10, date: ISODate( "2021-03-13T08:14:30Z" ) },
   { _id: 1, name: "Pepperoni", size: "medium", price: 20,
     quantity: 20, date : ISODate( "2021-03-13T09:13:24Z" ) },
   { _id: 2, name: "Pepperoni", size: "large", price: 21,
     quantity: 30, date : ISODate( "2021-03-17T09:22:12Z" ) },
   { _id: 3, name: "Cheese", size: "small", price: 12,
     quantity: 15, date : ISODate( "2021-03-13T11:21:39.736Z" ) },
   { _id: 4, name: "Cheese", size: "medium", price: 13,
     quantity:50, date : ISODate( "2022-01-12T21:23:13.331Z" ) },
   { _id: 5, name: "Cheese", size: "large", price: 14,
     quantity: 10, date : ISODate( "2022-01-12T05:08:13Z" ) },
   { _id: 6, name: "Vegan", size: "small", price: 17,
     quantity: 10, date : ISODate( "2021-01-13T05:08:13Z" ) },
   { _id: 7, name: "Vegan", size: "medium", price: 18,
     quantity: 10, date : ISODate( "2021-01-13T05:10:13Z" ) }
])
```

Calculate Total Order Quantity

The following aggregation pipeline example contains two [stages](https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference) and returns the total order quantity of medium size pizzas grouped by pizza name:

```bash theme={"system"}
db.orders.aggregate([
   // Stage 1: Filter pizza order documents by pizza size
   {
      $match: { size: "medium" }
   },
   // Stage 2: Group remaining documents by pizza name and calculate total quantity
   {
      $group: { _id: "$name", totalQuantity: { $sum: "$quantity" } }
   }
] )

```

For more consult mongodb docs here — &#x20;

&#x20;\> [https://www.mongodb.com/docs/manual/introduction/](https://www.mongodb.com/docs/manual/introduction/)
