Advanced data screening method based on MongoDB
By adopting advanced filtering methods based on MongoDB and JSON in the low-code form engine, the limitations of traditional data filtering methods are solved, enabling flexible and efficient filtering of multi-dimensional data, improving performance and user experience.
Patent Information
- Application Number
- CN202410960622.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-10-01
AI Technical Summary
The traditional data filtering method in low-code form design is limited when dealing with multi-scenario and multi-dimensional data filtering. It cannot meet the flexible and efficient needs of users, affecting the performance and user experience of the low-code form engine.
Adopting advanced filtering methods based on MongoDB and JSON data structures, by defining advanced filtering components, constructing JSON data and converting it into MongoDB aggregation conditions, filtering and displaying form data, supporting logical operations and dynamic parameter replacement, ensuring the flexibility of data filtering and efficiency.
It achieves flexible and efficient filtering of multi-dimensional data, improves the performance and user experience of low-code form engines, and meets the needs of complex business scenarios.
Smart Images

Figure CN118733596A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an advanced data screening method based on MongoDB. Background Art
[0002] With the continuous development of low-code technology, low-code platform products are increasing, and low-code form engines have become an important part of these products. In traditional low-code form design, the main data screening method is based on the query of a single field in the form or a global fuzzy query. However, with the continuous enrichment and complexity of user needs and business scenarios, traditional data screening methods appear to have certain limitations when dealing with the multi-scenario and multi-dimensional data screening of users at this stage. Therefore, there is an urgent need for an improved method that can more flexibly and efficiently meet the needs of multi-dimensional data screening, so as to improve the performance and user experience of the low-code form engine. Summary of the invention
[0003] In order to solve the above problems, the present invention introduces a new design concept, which is based on MongoDB and JSON data structure. By defining advanced filtering components and using JSON to carry the user's filtering requirements, the form data is filtered and displayed after being converted into MongoDB aggregation conditions by the background system.
[0004] The technical solution of the present invention is achieved by comprising the following steps:
[0005] S1: Define data filtering components, including predefined form field types and filtering methods.
[0006] S2: Build JSON based on user input. Build JSON data based on the field type, filter method, and user input defined in the filter component.
[0007] S3: Processes data in the background and converts it into filter conditions for MongoDB queries based on the incoming JSON format data.
[0008] S4: The database performs data screening and performs aggregate query operations using the form ID and the aggregate conditions constructed in step S3.
[0009] S5: Front-end data display, converting the data filtered out from the database into the data format and content required for front-end rendering.
[0010] The step S1 comprises:
[0011] S1.1: The filter component can choose to add form field filter conditions or filter condition groups. The filter conditions and filter condition groups can be combined into "and" or "or" logical operations. Form field filter conditions can be added to the filter condition group, and the filter conditions can also be combined into "and" or "or" logical operations.
[0012] S1.2: The form field types include text type, number type, time type, and member department, etc. The available filtering methods vary slightly between different types.
[0013] Preferably, step S3 comprises:
[0014] S3.1: If there is a member or department type field in the filter condition, and the matching value is the current member or the current department, the current logged-in user and the department the user belongs to are obtained, and the dynamic parameters in the filter condition are replaced.
[0015] S3.2: Obtain the corresponding permission group according to the currently logged-in user, and combine the filtering conditions of the permission group with the filtering conditions input by the user; the filtering conditions that may be involved in the permission group include all data, personal data, or customized filtering conditions based on form fields.
[0016] S3.3: Based on the filtering conditions and condition groups in the filtering component, the condition groups are taken as units, where the outermost single filtering condition is regarded as a condition group, and the filtering conditions for constructing the data are traversed in sequence. The filtering conditions in the condition group are combined with logical operations according to the configuration.
[0017] S3.4: Convert the constructed filter condition group expression into MongoDB's aggregation query condition. Perform logical operations between condition groups according to the configuration. If a subform exists, deconstruct the nested array field into multiple independent documents according to the subform ID through Aggregation.unwind (subform ID, Boolean.TRUE) to ensure that the array elements are expanded one by one to form a flat document structure.
[0018] Preferably, the step S3.3 further includes:
[0019] S3.3.1: Construct the deletion flag condition of the data, that is, obtain the data whose deletion flag deleteFlag is false.
[0020] S3.3.2: Recursively traverse each filter condition in the filter condition group.
[0021] S3.4.3: Verify whether the filtering method and the matching value Value entered by the user are legal. If not, skip the current filtering condition.
[0022] S3.4.4: Identify the filtering method in the filter conditions, and construct the filter conditions based on the filtering method and field type.
[0023] S3.4.5: Combine all filter conditions. When combining, select the corresponding aggregate expression Criteria.orOperator() or Criteria.andOperator() according to the filter condition combination type (logical AND / logical OR).
[0024] In step S2, the constructed JSON data mainly includes the form field ID, the form field type (text, number, time type...), the filtering method (equal to / not equal to, contain / not contain, dynamic filtering...), the filtering condition combination type (logical AND / logical OR) and the matching value value entered by the user.
[0025] Preferably, in step S1.2, the difference in screening methods is reflected in that the selectable screening methods for text type include equal / not equal, equal to any one / not equal to any one, contains / does not contain, is not empty / is empty; the number type has special greater than / less than, greater than or equal to / less than or equal to and range screening methods; the time type has a dynamic screening method, that is, the user can customize the time range or select today / this week / last month / next quarter, etc., and the member department screening can choose to match specified members, departments or the current user, current department. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is a work flow chart of the present invention;
[0027] Figure 2 This is an example diagram of the advanced screening component;
[0028] Figure 3 JSON data structure built for advanced filtering components;
[0029] Figure 4 Aggregate conditional structures for converted MongoDB data; DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] Example
[0032] like Figure 1 , Figure 2 , Figure 3 , Figure 4 As shown, an advanced data screening method based on MongoDB specifically includes the following N steps.
[0033] S1: Define data filtering components, including predefined form field types and filtering methods.
[0034] The following steps are involved:
[0035] S1.1: The filter component can choose to add form field filter conditions or filter condition groups. The filter conditions and filter condition groups can be combined into "and" or "or" logical operations. Form field filter conditions can be added to the filter condition group, and the filter conditions can also be combined into "and" or "or" logical operations.
[0036] S1.2: The form field types include text type, number type, time type and member department, etc. The selectable filtering methods vary slightly between different types. For example, the selectable filtering methods for text type include equal / not equal, equal to any one / not equal to any one, contain / not contain, not empty / empty; the number type has special greater than / less than, greater than or equal to / less than or equal to and range filtering methods; the time type has a dynamic filtering method, that is, the user can customize the time range or select today / this week / last month / next quarter, etc. The member department filtering can choose to match the specified member, department or the current user, current department.
[0037] S2: Construct JSON based on user input. Construct JSON data based on the field type, filter method and user input defined in the filter component; mainly including form field ID, form field type (text, number, time type...), filter method (equal to / not equal to, contains / does not contain, dynamic filter...), filter condition combination type (logical AND / logical OR) and matching Value input by the user.
[0038] S3: Processes data in the background and converts it into filter conditions for MongoDB queries based on the incoming JSON format data.
[0039] The following steps are involved:
[0040] S3.1: If there is a member or department type field in the filter condition, and the matching value is the current member or the current department, the current logged-in user and the department the user belongs to are obtained, and the dynamic parameters in the filter condition are replaced.
[0041] S3.2: Obtain the corresponding permission group according to the currently logged-in user, and combine the filtering conditions of the permission group with the filtering conditions input by the user; the filtering conditions that may be involved in the permission group include all data, personal data, or customized filtering conditions based on form fields.
[0042] S3.3: Based on the filtering conditions and condition groups in the filtering component, the condition groups are taken as units, where the outermost single filtering condition is regarded as a condition group, and the filtering conditions for constructing the data are traversed in sequence. The filtering conditions in the condition group are combined with logical operations according to the configuration.
[0043] The following steps are involved:
[0044] S3.3.1: Construct the deletion flag condition of the data, that is, obtain the data whose deletion flag deleteFlag is false.
[0045] S3.3.2: Recursively traverse each filter condition in the filter condition group.
[0046] S3.4.3: Verify whether the filtering method and the matching value Value entered by the user are legal. If not, skip the current filtering condition.
[0047] S3.4.4: Identify the filtering method in the filtering conditions, and construct the filtering conditions based on the filtering method and combined with the field type. The processing methods of different field types are slightly different.
[0048] Contains the following filtering methods:
[0049] Is empty / is not empty: Build the expression through Criteria.where(key).exists(Boolean.FALSE), Criteria.where(key).in("",null,) and Criteria.where(key).size(0).
[0050] Equal to / Not equal to: Process according to different field types. If it is a text type, The expression is constructed by using Criteria.where(key).is(value). If it is a time type, the time format is converted first, and then the expression is constructed by using Criteria.where(key).gte(start).lte(end). If it is a number type, it is converted to BigDecimal type first, and then the expression is constructed in the same way as the text type.
[0051] Equal to any one / Not equal to any one: Build an expression by using Criteria.where(key).in(values) or not.in().
[0052] Contains / does not contain: Translate special characters, if it is text or date type, The expression is constructed in the form of Criteria.where(key).regex(value,"i"), and if it is not contained, it corresponds to not.regex().
[0053] Dynamic range: If the field is of time type, get the start time and end time in the parameter, parse them into standard UTC time, and construct the expression through Criteria.where(key).gte(startTime).lt(endTime); if the field is of numeric type, convert the value in the parameter into BigDecimal type, and The expression can be constructed by using Criteria.where(key).gte(start) and Criteria.where(key).lte(end).
[0054] Greater than / less than: If it is a time type, it is converted to standard time first and then passed The expression is constructed by using Criteria.where(key).gt(date); if the field is of numeric type, the value in the parameter is converted to BigDecimal type, and the expression is constructed by using Criteria.where(key).gt(value).
[0055] S3.4.5: Combine all filter conditions. When combining, select the corresponding aggregate expression Criteria.orOperator() or Criteria.andOperator() according to the filter condition combination type (logical AND / logical OR).
[0056] S3.4: Convert the constructed filter condition group expression into MongoDB's aggregation query condition. Perform logical operations between condition groups according to the configuration. If a subform exists, deconstruct the nested array field into multiple independent documents according to the subform ID through Aggregation.unwind (subform ID, Boolean.TRUE) to ensure that the array elements are expanded one by one to form a flat document structure.
[0057] S4: The database performs data screening and performs aggregate query operations using the form ID and the aggregate conditions constructed in step S3.
[0058] S5: Front-end data display, converting the data filtered out from the database into the data format and content required for front-end rendering.
Claims
1. A method for advanced data screening based on MongoDB, characterized in that By defining advanced filtering components and JSON to carry users' data filtering needs, the background processing converts them into MongoDB aggregation conditions to filter and display the form data. The steps include: S1: Define data filtering components, including defining form field types and filtering methods. S2: Build JSON data based on user input. S3: Processes data in the background and converts it into filter conditions for MongoDB queries based on the incoming JSON format data. S4: The database performs data screening and performs aggregate query operations using the form ID and the aggregate conditions constructed in step S3. S5: Front-end data display, converting the data filtered out from the database into the data format and content required for front-end rendering.
2. The advanced data screening method based on MongoDB according to claim 1, characterized in that: The step S1 comprises: S1.1: The filter component can choose to add form field filter conditions or filter condition groups. The filter conditions and filter condition groups can be combined into "and" or "or" logical operations. Form field filter conditions can be added to the filter condition group, and the filter conditions can also be combined into "and" or "or" logical operations. S1.2: The form field types include text type, number type, time type and member department, etc. The selectable filtering methods vary slightly between different types. The selectable filtering methods for the text type include equal / not equal, equal to any one / not equal to any one, contain / not contain, not empty / empty; the number type has special greater than / less than, greater than or equal to / less than or equal to and range filtering methods; the time type has a dynamic filtering method, that is, the user can customize the time range or select today / this week / last month / next quarter, etc. The member department filtering can choose to match the specified member, department or the current user, current department.
3. The advanced data screening method based on MongoDB according to claim 1, characterized in that. The step S3 further comprises: S3.1: If there is a member or department type field in the filter condition, and the matching value is the current member or the current department, the current logged-in user and the department the user belongs to are obtained, and the dynamic parameters in the filter condition are replaced. S3.2: Obtain the corresponding permission group according to the currently logged-in user, and combine the filtering conditions of the permission group with the filtering conditions input by the user; the filtering conditions that may be involved in the permission group include all data, personal data, or customized filtering conditions based on form fields. S3.3: Based on the filtering conditions and condition groups in the filtering component, the condition groups are taken as units, where the outermost single filtering condition is regarded as a condition group, and the filtering conditions for constructing the data are traversed in sequence. The filtering conditions in the condition group are combined with logical operations according to the configuration. S3.4: Convert the constructed filter condition group expression into MongoDB's aggregation query condition. Perform logical operations between condition groups according to the configuration. If a subform exists, deconstruct the nested array field into multiple independent documents according to the subform ID through Aggregation.unwind (subform ID, Boolean.TRUE) to ensure that the array elements are expanded one by one to form a flat document structure.
4. The advanced data screening method based on MongoDB according to claim 3 is characterized in that: The step S3.3 also includes: S3.3.1: Construct the deletion flag condition of the data, that is, obtain the data whose deletion flag deleteFlag is false. S3.3.2: Recursively traverse each filter condition in the filter condition group. S3.4.3: Check whether the filter method and the matching value Value entered by the user are legal. If they are illegal, skip the current filter condition. S3.4.4: Identify the filter method in the filter condition, and construct the filter condition based on the filter method and field type. The processing methods of different field types are slightly different. S3.4.5: Combine all filter conditions. When combining, select the corresponding aggregate expression Criteria.orOperator() or Criteria.andOperator() according to the filter condition combination type (logical AND / logical OR).
5. According to the advanced data screening method based on MongoDB described in claim 4, the filtering method in the filtering condition includes: a. Empty / Not empty; b. Equal to / not equal to; c. Equal to any one / Not equal to any one; d. Included / Excluded; e. Dynamic range; f. Greater than / less than.
Citation Information
Patent Citations
Data condition filtering and screening method and screener
CN102436503A
Query implementation method of control with comparators
CN114840548A
Data screening method and device based on conditional expression
CN115186639A
General query method and device for database table and storage medium
CN115617795A
User grouping method and system based on multiple databases and storage medium
CN115829615A
