link scenarios to backend

This commit is contained in:
2025-03-15 11:23:55 +02:00
parent 6aad752ce3
commit 2a44578430
13 changed files with 233 additions and 75 deletions
+19 -1
View File
@@ -26,7 +26,7 @@ class Db {
try {
dbo = db.db(app.config.db.name);
this.instance = dbo;
for (let c of ['users', 'user_sessions', 'history', 'log', 'assets']){
for (let c of ['users', 'user_sessions', 'history', 'log', 'assets', 'scenarios']){
try {
await dbo.createCollection(c);
}catch(err){}
@@ -245,6 +245,24 @@ class Db {
ObjectId(id){
return new ObjectId(id);
}
/**
* Gets last asset Id from database, намира последния пореден идентификатор на обект в базата от данни
* @returns {Number} Last Asset Id, последен (най-голям) идентификатор
*/
async getLastId(collection){
let ag = await this.aggregate(collection, [
{
$group:{
_id: null,
max: {
$max: "$id",
},
},
},
]);
return ag.max || 0;
}
}
export { Db };