---
type: archive
area: archive
status: archived
date: 2026-05-03
created: 2026-05-03
updated: 1980-01-01
tags:
  - archive
---
- mongosh "mongodb://host:27017"
- access to mongo db server
## Comparison Query Operators

|Name|Description|
|---|---|
|[`$eq`](https://www.mongodb.com/docs/manual/reference/operator/query/eq/#mongodb-query-op.-eq)|Matches values that are equal to a specified value.|
|[`$gt`](https://www.mongodb.com/docs/manual/reference/operator/query/gt/#mongodb-query-op.-gt)|Matches values that are greater than a specified value.|
|[`$gte`](https://www.mongodb.com/docs/manual/reference/operator/query/gte/#mongodb-query-op.-gte)|Matches values that are greater than or equal to a specified value.|
|[`$in`](https://www.mongodb.com/docs/manual/reference/operator/query/in/#mongodb-query-op.-in)|Matches any of the values specified in an array.|
|[`$lt`](https://www.mongodb.com/docs/manual/reference/operator/query/lt/#mongodb-query-op.-lt)|Matches values that are less than a specified value.|
|[`$lte`](https://www.mongodb.com/docs/manual/reference/operator/query/lte/#mongodb-query-op.-lte)|Matches values that are less than or equal to a specified value.|
|[`$ne`](https://www.mongodb.com/docs/manual/reference/operator/query/ne/#mongodb-query-op.-ne)|Matches all values that are not equal to a specified value.|
|[`$nin`](https://www.mongodb.com/docs/manual/reference/operator/query/nin/#mongodb-query-op.-nin)|Matches none of the values specified in an array.|

pass to mongoDb instance : d9xgkV8GIZFzWfqv
### <mark style="background: #FF5582A6;">we need $and in some queries where we use and to retrieve data even if queries are anded by default in mongodb

</mark>

db.restaurants.find( {"name": /.*Reg.*/}, { "restaurant_id" : 1, "name":1,"borough":1, "cuisine" :1 } );
// Regex

![[Pasted image 20231218164410.png]]

![[Pasted image 20231218170525.png]]

``` JSON
[
{ $unwind:"$Joueurs":{"$Controls"},
$match:{"$Joueur.Controls.DateCtrl":{
$and:[
{$gte:"03/05/2005"},{$lte:"04/05/2005"}
]
}},
{$project:{"$Joueur.Nom":1}}
]
```

``` JSON
db.Equipe.updateOne(
	{"NumEq":3,"Joueurs.NumDossard": 4},
{
    $set: {
      "Joueurs.$.Controls.$[elem].Result": "N"
    }
  },
  {
    arrayFilters: [
      {
        "elem.DateCtrl": "03/11/05"
      }
    ]
  }
)
```


```JSON
db.exam2023.aggregate([
  { $unwind: "$modules" },
  { $match: { "modules.intitule": "NoSQL" } },
  {
    $set: {
      "moyGen": {
        $add: [
          { $multiply: ["$modules.infos.NoteControleContinue", 0.3] },
          { $multiply: ["$modules.infos.NoteExamen", 0.5] },
          { $multiply: ["$modules.infos.NoteTP", 0.2] }
        ]
      }
    }
  },
  { $project: { nom: 1, moyenGen: "$moyGen" } }
]);
```

```JSON
  {
    $sort: {
      CodePays: 1,
    },
  },
 ]
```
 
```JSON
db.Equipe.aggregate([
  {
    $match: { "NumEq": 6 }
  },
  {
    $unwind: "$Joueurs"
  },
  {
    $group: {
      _id: null,
      numberOfPlayers: { $sum: 1 }
    }
  }
]);

```

```JSON
db.Equipe.aggregate([
{$unwind:"$Joueurs"},
{$match:{"Joueurs.Nom":/^B/}},
{$project:{
_id:0,
Nom:"$Joueurs.Nom",
Prenom:"$Joueurs.Prénom"
}}
]
);
```

```json
db.items.aggregate([
  {
    $match: {
      itemName: {
        $regex: /^apple/,
        $options: 'i' // 'i' option makes the regex case-insensitive
      }
    }
  }
]);

```

`````json
db.items.aggregate([
  {
    $match: {
      itemName: {
        $regex: /apple$/,
        $options: 'i' // 'i' option makes the regex case-insensitive
      }
    }
  }
]);

```

```
db.Equipe.aggregate({$unwind:{'Joueurs'},$match:{$gt:{"NumDossard":10}},$project:{"Joueurs.Nom"})
```