Skip to content

Commit 7f7d204

Browse files
committed
fix: save decimal as decimal128 in mongo
1 parent a9c1355 commit 7f7d204

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

adminforth/dataConnectors/mongo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import dayjs from 'dayjs';
22
import { MongoClient } from 'mongodb';
3+
import { Decimal128 } from 'bson';
34
import { IAdminForthDataSourceConnector, IAdminForthSingleFilter, IAdminForthAndOrFilter, AdminForthResource } from '../types/Back.js';
45
import AdminForthBaseConnector from './baseConnector.js';
56

@@ -109,7 +110,7 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
109110
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
110111
return value ? true : false;
111112
} else if (field.type == AdminForthDataTypes.DECIMAL) {
112-
return value?.toString();
113+
return Decimal128.fromString(value?.toString());
113114
}
114115
return value;
115116
}
@@ -140,6 +141,7 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
140141
// const columns = resource.dataSourceColumns.filter(c=> !c.virtual).map((col) => col.name).join(', ');
141142
const tableName = resource.table;
142143

144+
143145
const collection = this.client.db().collection(tableName);
144146
const query = filters.subFilters.length ? this.getFilterQuery(resource, filters) : {};
145147

0 commit comments

Comments
 (0)