-
Notifications
You must be signed in to change notification settings - Fork 22
fix: fix filter by autogenerated _id for mongodb #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from 1 commit
4118cce
5286814
08154a9
5ba0c0e
7a7e08e
be497f3
80a250f
429a853
e4181ee
77e28e8
a05ea7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import dayjs from 'dayjs'; | ||
| import { MongoClient } from 'mongodb'; | ||
| import { Decimal128 } from 'bson'; | ||
| import { Decimal128, ObjectId } from 'bson'; | ||
| import { IAdminForthDataSourceConnector, IAdminForthSingleFilter, IAdminForthAndOrFilter, AdminForthResource } from '../types/Back.js'; | ||
| import AdminForthBaseConnector from './baseConnector.js'; | ||
|
|
||
|
|
@@ -64,14 +64,6 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS | |
| }, {}); | ||
| } | ||
|
|
||
| getPrimaryKey(resource) { | ||
| for (const col of resource.dataSourceColumns) { | ||
| if (col.primaryKey) { | ||
| return col.name; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| getFieldValue(field, value) { | ||
| if (field.type == AdminForthDataTypes.DATETIME) { | ||
| if (!value) { | ||
|
|
@@ -89,6 +81,9 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS | |
| return !!value; | ||
| } else if (field.type == AdminForthDataTypes.DECIMAL) { | ||
| return value?.toString(); | ||
| } else if (field.name === '_id' && !field.fillOnCreate) { | ||
| // if "_id" was created by mongo it will be ObjectId | ||
| return value?.toString(); | ||
|
||
| } | ||
|
|
||
| return value; | ||
|
|
@@ -111,6 +106,9 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS | |
| return value ? true : false; | ||
| } else if (field.type == AdminForthDataTypes.DECIMAL) { | ||
| return Decimal128.fromString(value?.toString()); | ||
| } else if (field.name === '_id' && !field.fillOnCreate) { | ||
| // if "_id" was created by mongo it supposed to be saved as ObjectId | ||
| return ObjectId.createFromHexString(value); | ||
|
||
| } | ||
| return value; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Astaldos will it brake something if we will remove
&& !field.fillOnCreate?I mean for the case if user returns object id in fillOnCreate.