---
# System prepended metadata

title: Session types

---

# Session types

## Option 1 

> Collection sessions

```
{
    sessionId: Number,
    sessionTypeIds: Number[]
}
```

> Collection sessionsTypes
```
{
    sessionTypeId: Number,
    name: String,
    sessionTtl: Number
}
```

| id | name |
| -- | ---- |
| 0  | chat |
| 1  | call |
| 2  | notification |
| 3  | internal |
| 4  | external |
| 5  | public channel  |
| 6  | private channel |
| 7  | group channel |


> direct internal session => 0 + 3
> group session => 0 + 3 + 7
> private channel => 0 + 3 + 6
> public channel  => 0 + 3 + 5
> universal channel => 0 + 3 + 4 + 6
> external session => 0 + 4


DB
```
// GET all internal session
db.sessions.find({
    sessionTypes: 3
})

// GET all channels
db.sessions.find({
    sessionTypes: { $in: [ 5, 6] }
})

// GET universal channels
db.sessions.find({
    sessionTypes: { $all: [ 0, 3, 4, 6], $size: 4 }
})

// GET group sessions
db.sessions.find({
    sessionTypes: { $all: [0,3,7], $size: 3 },
})

// GET direct sessions (group, self, one to one)
db.sessions.find({
    $or: [
        { sessionTypes.0: { $all: [0,3], $size: 2} },
        { sessionTypes.0: { $all: [0,3,7], $size: 3} },
    ]
})

// GET external sessions
db.sessions.find({
   sessionTypes.0: { $all: [0,4], $size: 2},
})
```

### Option 2

> Collection sessions
```
{
    sessionId: Number,
    sessionTypeId: Number,
}
```

> Collection sessionTypes
```
{
    sessionTypeId: Number,
    canBeConvertedToIds: Number[],
    systemReference: String,
    sessionTtl: Number
}
```


| id | name                  | canBeConvertedToIds(childSessionTypeIds) | 
| -- | --------------------- | ------------------- |
| 0  | direct sesison        | []                  | 
| 1  | group session         | []                  | 
| 2  | private channel       | [7,3]               | 
| 3  | public channel        | [2]                 | 
| 4  | external session      | []                  | 
| 5  | call external         | []                  |
| 6  | notification          | []                  | 
| 7  | universal session     | []                  | 


API
```
> return only direct sessions
GET /sessions?sessionTypeIds=0

> return only direct sessions and group session
GET /sessions?sessionTypeIds=0,1
```

DB
```
> return only direct sessions
db.sessions.find({ sessionTypeId: 0 })

> return only direct sessions and group session
db.sessions.find({ sessionTypeId: { $in: [0,1] } })
```