Data query method and device, electronic equipment and storage medium
By using AOP aspect information and query permission identifiers in MongoDB, the problem of code duplication was solved, efficient data pagination queries were achieved, and the development efficiency and security of the system were improved.
Patent Information
- Application Number
- CN202311257832.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-26
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-09-26
AI Technical Summary
Existing technologies require different processing codes to be set up for different query content when querying data, resulting in a lot of similar code in the project, which affects development efficiency and is prone to system security vulnerabilities.
By using AOP aspect information and query permission identifiers, we can obtain aspect information of the distributed document storage database MongoDB, indicating whether data classes, fields, and values support paginated queries, receiving query requests, and performing queries under the preset permission identifier, thereby reducing the duplication of processing code for MongoDB.
It improves the flexibility, logic, and stability of the code, reduces similar code, and enhances development efficiency and system security.
Smart Images

Figure CN117633330B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, and in particular to a data query method, apparatus, electronic device and storage medium. Background Technology
[0002] With the development of internet technology, in the field of visualization development, there are often application scenarios where, when users query data, the backend code queries the database, and the database returns a large amount of data at once. The number of returned data records is large, and the frontend web page cannot fully display the data content, resulting in long frontend page loading time and high server pressure. This requires the use of list display and data pagination technology to display the data returned by the database in a list and pagination format.
[0003] Current pagination query logic typically involves setting up query and processing code in the program's backend. Based on this code, the database is paginated, and the retrieved data is displayed on the frontend webpage after pagination. However, different queries require different processing code, resulting in a large amount of similar code within the project. This can easily impact development progress and increase the risk of system security vulnerabilities. Therefore, there is an urgent need to design a solution to reduce similar code and improve system development efficiency. Summary of the Invention
[0004] This application provides a data query method, apparatus, electronic device, and storage medium to solve the problems of cumbersome code and low development efficiency in existing query programs.
[0005] To achieve the above objectives, this application adopts the following technical solution: Firstly, a data query method is provided, comprising: obtaining AOP aspect information corresponding to the distributed document storage database MongoDB; the AOP aspect information is used to indicate whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries; receiving a query request; the query request includes query content and a query permission identifier; if the query permission identifier is a preset identifier, querying from MongoDB according to the query content and the AOP aspect information to obtain query results; the query results include data that matches the query content and supports paginated queries.
[0006] Optionally, receiving query requests includes: receiving an initial query request through a web portal; marking the web portal and adding a preset query permission identifier to the initial query request through the web portal to obtain the query request; the query permission identifier is used to reflect whether the initial query request through the web portal has permission to access MongoDB.
[0007] Optionally, obtain the AOP aspect information corresponding to the distributed document storage database MongoDB, including: determining whether each data class supports paginated queries based on the attribute information corresponding to each data class, determining whether the fields of each data class support paginated queries based on the identifiers of the fields of each data class, and determining whether the values corresponding to each field support paginated queries based on whether the values corresponding to each field are empty, thus obtaining the AOP aspect information.
[0008] Optionally, based on the field identifiers of each data class, determine whether the fields of each data class support pagination queries, including: identifying the fields of each data class and setting field identifiers for each field; for any given field, if the field identifier is the target identifier, determine that the field supports pagination queries, and if the field identifier is not the target identifier, determine that the field does not support pagination queries.
[0009] Secondly, a data query device is provided, comprising an acquisition unit, a receiving unit, and a processing unit. The acquisition unit is used to acquire AOP aspect information corresponding to the distributed document storage database MongoDB. The AOP aspect information is used to indicate whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries. The receiving unit is used to receive query requests, which include query content and query permission identifiers. The processing unit is used to perform a query from MongoDB based on the query content and AOP aspect information, when the query permission identifier is a preset identifier, to obtain query results. The query results include data that matches the query content and supports paginated queries.
[0010] Optionally, the receiving unit receives query requests and is specifically used for: receiving an initial query request through a web portal; marking the web portal and adding a preset query permission identifier to the initial query request through the web portal to obtain the query request; the query permission identifier is used to reflect whether the initial query request through the web portal has permission to access MongoDB.
[0011] Optionally, the AOP aspect information corresponding to the distributed document storage database MongoDB is obtained. The obtaining unit is specifically used to: determine whether each data class supports pagination query based on the attribute information corresponding to each data class; determine whether the fields of each data class support pagination query based on the identifier of the fields of each data class; and determine whether the values corresponding to each field support pagination query based on whether the values corresponding to each field are empty, thereby obtaining the AOP aspect information.
[0012] Optionally, based on the field identifiers of each data class, determine whether the fields of each data class support pagination queries and obtain units. Specifically, this is used to: determine the fields of each data class and set field identifiers for each field; for any field, if the field identifier is the target identifier, determine that the field supports pagination queries, and if the field identifier is not the target identifier, determine that the field does not support pagination queries.
[0013] Thirdly, an electronic device is provided, comprising: a processor and a memory for storing processor-executable instructions; wherein the processor is configured to execute instructions to implement the data query method of the first aspect described above.
[0014] Fourthly, a computer-readable storage medium is provided, on which instructions are stored, such that when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is able to perform the data query method of the first aspect.
[0015] The technical solution provided in this application provides at least the following beneficial effects: It obtains AOP aspect information corresponding to the distributed document storage database MongoDB. This AOP aspect information indicates whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries. It receives query requests, which include query content and query permission identifiers. When the query permission identifier is a preset identifier, it queries MongoDB based on the query content and AOP aspect information to obtain query results. The query results include data that matches the query content and supports paginated queries. Because it does not set different processing code based on different query content when querying the MongoDB database, but instead sets corresponding AOP aspect information and query permission identifiers based on the MongoDB database, it allows for the setting of multiple pointcuts. During program execution, it processes query requests and paginated query data based on the pointcuts and query permission identifiers, efficiently executing paginated query logic, reducing similar code in the project, and improving code flexibility, logic, and stability. Compared to existing technologies that set different processing code based on different query content when executing pagination query logic, this application uses AOP aspect information and query permission identifiers, which reduces similar code in the project and improves the flexibility, logic and stability of the code. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of the structure of a data query system provided in an embodiment of this application; Figure 2 This is one of the flowcharts illustrating a data query method provided in an embodiment of this application; Figure 3 A second schematic flowchart illustrating a data query method provided in an embodiment of this application; Figure 4 The third flowchart illustrates a data query method provided in this application embodiment; Figure 5 This is a schematic diagram of the structure of a data query device provided in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0019] It should be noted that in the embodiments of this application, the words "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0020] It should also be noted that in the embodiments of this application, "of", "corresponding", and "corresponding" can sometimes be used interchangeably. It should be pointed out that when their differences are not emphasized, their meanings are consistent.
[0021] To facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish the same or similar items with essentially the same function and effect. Those skilled in the art can understand that the terms "first" and "second" are not intended to limit the quantity or execution order.
[0022] Before providing a detailed explanation of the embodiments of this application, some relevant technical terms and technologies involved in the embodiments of this application will be introduced first.
[0023] With the development of internet technology, in the field of visualization development, there are often application scenarios where, when users query data, the backend code queries the database, and the database returns a large amount of data at once. The number of returned data records is large, and the frontend web page cannot fully display the data content, resulting in long frontend page loading time and high server pressure. This requires the use of list display and data pagination technology to display the data returned by the database in a list and pagination format.
[0024] The database used in this application can be MongoDB, a distributed document storage database. MongoDB is a database based on distributed file storage. Written in C++ (C++ Plus Plus), it aims to provide scalable, high-performance data storage solutions for World Wide Web (WEB) applications. MongoDB is a product between relational and non-relational databases, and is the most feature-rich and relational-database-like among non-relational databases. Under high load, server performance can be guaranteed by adding more nodes.
[0025] MongoDB's storage structure differs from traditional relational databases, primarily consisting of three units: Documents, Collections, and Databases. A document is the most basic unit in MongoDB, composed of Binary Structured Object Notation (BSON) key-value pairs, similar to a row in a relational database. A collection can contain multiple documents, similar to a table in a relational database. A database can contain multiple collections, and multiple databases can be created in MongoDB, similar to databases in relational databases.
[0026] MongoDB stores data records as documents (more specifically, BSON documents), which are aggregated in collections. A database stores one or more collections of documents. A record in MongoDB is a BSON document, a data structure composed of key-value pairs, similar to JavaScript ObjectNotation (JSON), and is the basic unit of data in MongoDB. Field values may include other documents, arrays, and arrays of documents.
[0027] BSON is a computer data interchange format primarily used for data storage and network transmission in MongoDB databases. It is a binary representation that can represent simple data structures, associative arrays (called "objects" or "documents" in MongoDB), and various data types within MongoDB. The name BSON is derived from JSON, meaning Binary JSON.
[0028] The backend code that retrieves and processes data from the database can use Java as its programming language. Java is an object-oriented programming language that not only absorbs the advantages of C++ but also eliminates difficult-to-understand concepts such as multiple inheritance and pointers in C++. Therefore, Java is both powerful and easy to use. As a representative of statically typed object-oriented programming languages, Java excellently implements object-oriented theory, allowing programmers to perform complex programming with an elegant mindset.
[0029] When a user queries the database, the database returns a large amount of data at once, with a large number of data entries. The front-end webpage cannot display all the data content, resulting in long front-end page loading times and high server load. Therefore, it is necessary to use list display and data pagination technology to display the data returned by the database in a list format.
[0030] Data pagination is a commonly used page display technology. Pagination can improve system performance by reducing the amount of page data processing.
[0031] When building query programs for MongoDB databases using Java, different processing code needs to be set up depending on the query content. This results in a lot of similar code in the project, which can easily affect the project's development progress and also make the system security vulnerabilities more likely.
[0032] In view of the above problems, this application provides a data query method that aims to simplify the judgment code of matching rules and improve the development efficiency of web pages.
[0033] The data query method provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0034] The data query method provided in this application can be applied to a data query system. For example... Figure 1 As shown, the data query system 10 includes a server 11 and a data query device 12. The server 11 and the data query device 12 can be connected via a wired or wireless connection; this embodiment does not limit the connection in this way.
[0035] Server 11 can be used to store data from a MongoDB database.
[0036] The data query device 12 can be used to retrieve data content from the MongoDB database from the server 11. The data query device 12 queries and processes the data content in the MongoDB database according to the user's request, obtains the processed data, and sends it to the user. The specific query and processing process can be found in the following embodiments, which will not be repeated here.
[0037] It should be noted that server 11 can be a single server or a server cluster consisting of multiple servers. In some embodiments, the server cluster can also be a distributed cluster. Optionally, the server can also be implemented on a cloud platform, such as a private cloud, public cloud, hybrid cloud, community cloud, distributed cloud, inter-cloud, and multi-cloud, or any combination thereof. This application embodiment does not impose any limitations on this.
[0038] The data query device 12 can be any terminal device with the function of acquiring and processing database data, such as a mobile phone, tablet computer, desktop computer, laptop computer, notebook computer, ultra-mobile personal computer (UMPC), handheld computer, netbook, personal digital assistant (PDA), wearable electronic device, smartwatch, etc. The data query device 12 can also be any virtual network platform or virtual network device with the function of acquiring and processing database data.
[0039] Figure 2 This is a flowchart illustrating a data query method according to some exemplary embodiments. In some embodiments, the following data query method can be applied to, for example... Figure 1 The data query system shown can also be applied to other similar scenarios.
[0040] like Figure 2 As shown, the data query method provided in this application embodiment includes the following S201-S203.
[0041] S201. Obtain the AOP aspect information corresponding to the distributed document storage database MongoDB.
[0042] Among them, AOP aspect information is used to indicate whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries.
[0043] As one possible approach, the data query device obtains the AOP aspect information corresponding to the MongoDB database. The AOP aspect information is used to indicate whether each data class in the MongoDB database supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries.
[0044] It's important to note that Aspect-Oriented Programming (AOP) is a technique that uses pre-compilation and runtime dynamic proxies to achieve unified maintenance of program functionality. AOP is a continuation of Object-Oriented Programming (OOP), a hot topic in software development, and a derivative paradigm of functional programming. AOP allows for the isolation of different parts of business logic, thereby reducing coupling between them, improving program reusability, and increasing development efficiency.
[0045] AOP (Aspect-Oriented Programming) is a programming paradigm that breaks down applications into multiple concerns. In AOP design, specific behaviors (such as logging and security checks) are separated from the main body of the application, allowing for more flexible management and control over these behaviors.
[0046] AOP can include five advice types: before advice, after advice, return advice, exception advice, and around advice. Before advice uses the `@Before` annotation and typically executes before the method. After advice uses the `@After` annotation and typically executes after the method. Return advice uses the `@AfterRunning` annotation and typically executes after the method returns a result. Exception advice uses the `@AfterThrowing` annotation and typically executes after the method throws an exception. Around advice uses the `@Around` annotation and typically executes around the method. Around advice is the most powerful of all advice types, providing comprehensive control over join points and even controlling whether a join point is executed. This application uses the around advice type in AOP.
[0047] These five advice annotations can also be followed by specific parameters to specify which aspect method triggers the annotation during which method execution. By using pointcut expressions, AOP technology can be applied to the project's code.
[0048] By adding a pointcut expression parameter to the annotation, one or more specific join points can be located using an expression. The syntax of a pointcut expression is: "execution([access modifier] [return type] [simple class name / fully qualified class name] [method name]([parameter list]))". Two commonly used special symbols in the expression are the asterisk (*). The asterisk (") represents all, and can also represent any numeric type. The period ("...") represents any type or file in any path.
[0049] For example, the data query device obtains the AOP aspect information corresponding to the MongoDB database. The AOP pointcut expression set by the data query device can be "@Around("execution( com.cloud.worShipCloud.controller. . (..))") ". Based on the AOP pointcut expression set by the data query device, the AOP notification type is determined to be around notification, the notification annotation is set to @Around, and the first asterisk " "Represents any return type, specify the second asterisk" "Represents any class name under the path, and determines the third asterisk" "..." represents any method within the class, and "..." represents any parameter of the method. That is, the data query device can determine any method of any class under the path "com.cloud.worShipCloud.controller" with the aspect configured. This is merely an example, and this application does not impose any limitations on it.
[0050] The data query device obtains AOP aspect information based on the AOP pointcut expression. Specifically, the data query device determines whether each data class supports pagination based on the attribute information corresponding to each data class, whether each data class field supports pagination based on the field identifier, and whether each field value supports pagination based on whether the corresponding value is empty, thus obtaining the AOP aspect information.
[0051] For example, the data query device encapsulates field information from the MongoDB database into a data class. Based on the attribute information corresponding to the data class `AdminUserInfo`, the data query device determines whether the `AdminUserInfo` class supports paginated queries. Here, the `AdminUserInfo` class is a business entity class and also the encapsulation class for paginated query information. The data query device obtains the `Class` class of the proxied class object, displays the object's `Class` name `AdminUserInfo`, judges the attribute information of the proxied class object, obtains the judgment result, and determines whether the data class supports paginated queries based on the judgment result.
[0052] The data query device identifies the fields of each data class and assigns field identifiers to each field. Specifically, it identifies the fields within the AdminUserInfo class, which contains numerous fields such as page number (pageSize), page, real name (realName), phone number, and gender (sex). Based on the identifiers assigned to these fields, the data query device determines whether a field supports pagination. In other words, the device can determine whether a field can be used as a key for pagination queries and whether the query results can be returned to the data query device based on its corresponding field identifiers.
[0053] The data query device determines that a field supports pagination if its identifier matches the target identifier, and does not support pagination if its identifier does not match the target identifier. In other words, if the field identifier matches the target identifier, the data query device determines that the field supports pagination but cannot display the results to the user. If the field identifier does not match the target identifier, the data query device determines that the field does not support pagination.
[0054] For example, the data query device sets field identifiers for each field. The data query device sets a field identifier as a non-target identifier, that is, it sets the @PagerIgnore field identifier as a pagination query identifier, indicating which fields are not key to pagination queries. This means users cannot use fields marked with @PagerIgnore to query data in the MongoDB database. The data query device also sets a field identifier as a target identifier, that is, it sets the @JsonIgnore field identifier as a data return identifier, indicating which fields are considered confidential data and cannot be returned to the user. This means users cannot view the data in the MongoDB database corresponding to fields marked with @JsonIgnore.
[0055] The data query device sets field identifiers for fields such as page number (pageSize), page (page), user ID (userId), real name (realName), phone number (phone), gender (sex), and password (password). The data query device sets the `@JsonIgnore` field identifier for page number (pageSize), page (page), and password (password), and the `@PagerIgnore` field identifier for user ID (userId) and password (password). Based on the field identifiers, the data query device determines that the user ID (userId) and password fields are not used as pagination query keys, that page number (pageSize), page (page), and password (password) are confidential data and not returned to the user, and that the real name (realName), phone number (phone), and gender (sex) can be used as pagination query keys and returned to the user.
[0056] S202, Receive query request.
[0057] The query request includes the query content and the query permission identifier.
[0058] One possible approach is for the data query device to obtain the AOP aspect information corresponding to the MongoDB database and then receive the user's query request. The query request includes the query content and the query permission identifier.
[0059] The data query device receives initial query requests through a web portal, marks the web portal, adds a preset query permission identifier to the initial query request, and thus obtains the query request. The query permission identifier reflects whether the initial query request through the web portal has permission to access MongoDB.
[0060] It should be noted that user query requests can be HTTP requests, which are request messages from the client to the server. These include: the request method for the resource, the resource identifier, and the protocol used, all in the first line of the message.
[0061] The data query device can set relevant information for a web portal. The web portal can include a web interface. The data query device sets relevant network information for this interface, such as the request method and request path.
[0062] For example, the data query device can set the request method of the web interface to a POST request, i.e., an HTTP response request, with the request path being " / userInfo". The data query device receives the user's initial query request through the web portal and marks the web portal. That is, the data query device receives and processes the user's initial query request through the web portal. The data query device processes the request based on the information contained in the user's initial query request. For example, if the user initiating the request is a regular user without permission to query the MongoDB database, the data query device will reject the user's request. If the user initiating the request is an administrator with permission to query the MongoDB database, the user's request can be processed through the web portal. The data query device processes the user's request, adds a preset query permission identifier @MongdbQueryPager to the initial query request through the web portal according to the marking processing of the web portal, and the data query device determines the query request.
[0063] S203. If the query permission identifier is the preset identifier, query from MongoDB according to the query content and AOP aspect information to obtain the query results.
[0064] The query results include data that matches the query content and supports pagination.
[0065] As one possible approach, when the query permission identifier is set to a preset identifier, the data query device queries data from the MongoDB database based on the query content and AOP aspect information to obtain query results, which include data that matches the query content and supports pagination.
[0066] For example, the data query device uses Java reflection technology to obtain the processed query request, determines the query permission identifier of the query request, and if the query request contains the query permission identifier @MongdbQueryPager, the data query device determines that the query permission identifier of the query request is a preset identifier. The data query device queries the data in the MongoDB database according to the query content set by the user, and obtains the query results. The query content set by the user can be field information in the MongoDB database, or the data corresponding to the field. For example, querying all real names (realName) in the MongoDB database, or all data information corresponding to the real name (realName) "Zhang San", etc. Based on the field information selected by the user and the corresponding field identifier, the data query device processes the queried data into pages and sends them to the user.
[0067] It should be noted that Java reflection allows, at runtime, all attributes and methods of any class to be known, and any method and attribute of any object to be invoked. This ability to dynamically obtain information and dynamically invoke object methods is called Java's reflection mechanism.
[0068] For example, such as Figure 3 As shown, the data query system starts and begins executing system programs. The system automatically creates an AOP aspect based on a specified path. The user initiates a network query request, requesting the web entry method within the AOP aspect. The data query device, using Java reflection technology, transforms the query request into a query method and obtains the processed query method. It then determines whether the query method is marked with the query permission identifier `@MongdbQueryPager`. If the query method is not marked with `@MongdbQueryPager`, it cannot query data in the MongoDB database, and the data query device processes the query method according to its execution logic. Specifically, it returns the query method in the order of controller, service, and MongoDB. If the query method is marked with `@MongdbQueryPager`, it can query data in the MongoDB database. The data query device then obtains the request information from the query method, including pagination information and query keywords, according to its query logic.
[0069] The data query device retrieves query and pagination information based on the data storage characteristics of the MongoDB database. Specifically, within the stored content of the MongoDB database, the data query device sets the field information of the stored entity as the key and the corresponding value information as the value. Using Java reflection technology, the data query device obtains the pagination information, the field names of the query keywords, and the corresponding values from the query method. It then uses the field names of the query keywords as the key and the corresponding values as the value in the MongoDB database query method, assembling the relevant pagination query information and encapsulating it into a pagination query encapsulation object. Based on this pagination query encapsulation object, the data query device queries the MongoDB database through the corresponding interface, retrieves data records that meet the conditions, performs pagination processing, and returns the uniformly encapsulated data to the user.
[0070] For example, such as Figure 4 As shown, the AOP aspect processing logic in the data query device specifically includes: The data query device obtains and intercepts the list of all input parameters of the interface from the pointcut set by the AOP aspect, i.e., obtains the query method. The data query device determines whether the parameter list is empty. If the parameter list is empty, the data query device does not perform interception processing, executes according to the program logic, and returns, ending the current operation. If the parameter list is not empty, the data query device sequentially obtains the proxied object, the proxied method, and the list of input parameter types of the proxied method in the parameter list, and determines whether the proxied object is marked with the query permission identifier @MongdbQueryPager. If it is not marked, the data query device executes according to the program logic and returns, ending the current operation. If it is marked, the data query device uses JAVA reflection technology to sequentially process each field of the input parameter object in the proxied method. That is, the data query device determines whether the field of the input parameter object is marked with the @PagerIgnore field identifier. If the field is marked, the data query device ends the processing of that field and executes the next field of the input parameter object in the proxied method. If the field is not marked, the data query device determines that the field participates in keyword retrieval and proceeds to the next step.
[0071] The data query mechanism uses Java reflection to obtain the name and value of the field. If the value is empty, the mechanism ends processing that field and proceeds to the next field in the proxied method's parameter object. If the value is not empty, the mechanism determines if it is a pagination information field (page number (pageSize) or page). If it is, the mechanism extracts the corresponding value for use when encapsulating the pagination information class. If it is not a pagination information field, the mechanism uses its field name as the key for the MongoDB database query, with the corresponding value being the value associated with the query key. The mechanism then adds this value to the query object. Finally, the mechanism checks if there are any unprocessed fields in the parameter object. If so, it proceeds to the next field in the proxied method's parameter object.
[0072] The data query device sets the query condition field "_class" to the full pathname of the input parameter object of the currently proxied method. When storing business data in the MongoDB database, the "_class" field is automatically added, with its value being the full pathname of the currently stored object. The data query device can use this information to distinguish the stored data tags of different business entities. The data query device calls the Application Programming Interface (API) to count the total number of records matching the query conditions. If the number of records is less than or equal to 0, the data query device encapsulates all information, executes the logic, and returns it to the web client for display, avoiding unnecessary queries to the MongoDB database and reducing the query pressure on the MongoDB database. If the number of records is greater than 0, the data query device calls the API to query the MongoDB database, retrieves the specified information, encapsulates it, executes the logic, and returns it to the web client for display. The data query device then terminates the current aspect processing logic.
[0073] For example, when the data query device starts the system, the user can use the interface testing tool Postman to initiate a GET / POST request. The request address can be "http: / / xx:xx / xx / query". The request sets the value of the field pageSize to 5, which means 5 records are displayed per page, and the field page to 0, which means the page number starts from 0, indicating the first page. The user information of the user with the field realName of test111 in the MongoDB database is queried. The data query device encapsulates and returns the retrieved information. Based on the field identifiers, it processes the data retrieved from the MongoDB database and returns the processed data to the user. Specifically, it encapsulates the following data: {"code": "0", "msg": "Operation successful", "total": 1, "userId": "1121124818171740160", "realName": "test111", "phone": "11111111111", "sex": 0, "updateTime": 1687339913457, "pageSize": 5, "page": 0} and returns it to the data query device. The data query device processes this data to obtain {"realName": "test111", "phone": "11111111111", "sex": 0}, which is then returned to the user.
[0074] The data query device uses the interface testing tool Postman to obtain the corresponding test results. Specifically, the test case execution result code is "-1" (non-zero indicates failure), msg represents the success or failure message, result.total is the number of records that meet the conditions, result.pageSize is the number of records displayed per page, result.page is the current page number, and result.data is the returned data list information. Sensitive fields marked with @JsonIgnore are not returned. Based on the test results, the data query device determines that the verification result meets the expected requirements, and the system can perform paginated queries on data in the MongoDB database according to user requests.
[0075] The technical solution provided in this application provides at least the following beneficial effects: It obtains AOP aspect information corresponding to the distributed document storage database MongoDB. This AOP aspect information indicates whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries. It receives query requests, which include query content and query permission identifiers. When the query permission identifier is a preset identifier, it queries MongoDB based on the query content and AOP aspect information to obtain query results. The query results include data that matches the query content and supports paginated queries. Because it does not set different processing code based on different query content when querying the MongoDB database, but instead sets corresponding AOP aspect information and query permission identifiers based on the MongoDB database, it allows for the setting of multiple pointcuts. During program execution, it processes query requests and paginated query data based on the pointcuts and query permission identifiers, efficiently executing paginated query logic, reducing similar code in the project, and improving code flexibility, logic, and stability. Compared to existing technologies that set different processing code based on different query content when executing pagination query logic, this application uses AOP aspect information and query permission identifiers, which reduces similar code in the project and improves the flexibility, logic and stability of the code.
[0076] The above embodiments mainly describe the solutions provided by the embodiments of this application from the perspective of an apparatus (device). It is understood that, in order to implement the above methods, the apparatus or device includes hardware structures and / or software modules corresponding to the execution of each method flow. These hardware structures and / or software modules corresponding to the execution of each method flow can constitute a material information determination apparatus. Those skilled in the art should readily recognize that, in conjunction with the algorithm steps of the various examples described in the embodiments of the invention herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in a hardware or computer software-driven hardware manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0077] This application embodiment can divide the device or equipment into functional modules according to the above method examples. For example, the device or equipment can be divided into functional modules corresponding to each function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0078] Figure 5 This is a schematic diagram illustrating the structure of a data query device according to an exemplary embodiment. (Refer to...) Figure 5 As shown, the data query device 30 provided in this application embodiment includes an acquisition unit 301, a receiving unit 302, and a processing unit 303.
[0079] The acquisition unit 301 is used to acquire AOP aspect information corresponding to the distributed document storage database MongoDB; the AOP aspect information is used to indicate whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries; the receiving unit 302 is used to receive query requests, the query requests including query content and query permission identifiers; the processing unit 303 is used to perform queries from MongoDB according to the query content and AOP aspect information, when the query permission identifier is a preset identifier, to obtain query results; the query results include data that matches the query content and supports paginated queries.
[0080] Optionally, the receiving unit 302 receives a query request and is specifically used to: receive an initial query request through a web portal; mark the web portal and add a preset query permission identifier to the initial query request through the web portal to obtain the query request; the query permission identifier is used to reflect whether the initial query request through the web portal has permission to access MongoDB.
[0081] Optionally, the AOP aspect information corresponding to the distributed document storage database MongoDB is obtained. The obtaining unit 301 is specifically used to: determine whether each data class supports pagination query based on the attribute information corresponding to each data class, determine whether the fields of each data class support pagination query based on the identifier of the fields of each data class, and determine whether the values corresponding to each field support pagination query based on whether the values corresponding to each field are empty, thereby obtaining the AOP aspect information.
[0082] Optionally, based on the identifier of each data class's field, determine whether the fields of each data class support pagination queries. The acquisition unit 301 is specifically used to: determine the fields of each data class and set field identifiers for each field; for any field, if the field identifier is the target identifier, determine that the field supports pagination queries, and if the field identifier is not the target identifier, determine that the field does not support pagination queries.
[0083] Figure 6 This is a schematic diagram of the structure of an electronic device provided in this application. For example... Figure 6The electronic device 40 may include at least one processor 401 and a memory 402 for storing processor-executable instructions, wherein the processor 401 is configured to execute the instructions in the memory 402 to implement the data query method in the above embodiments.
[0084] In addition, the electronic device 40 may also include a communication bus 403 and at least one communication interface 404.
[0085] Processor 401 may be a processor (central processing unit, CPU), microprocessor unit, ASIC, or one or more integrated circuits for controlling the execution of programs according to the present application.
[0086] The communication bus 403 may include a path for transmitting information between the aforementioned components.
[0087] Communication interface 404 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.
[0088] Memory 402 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Memory 402 may exist independently and be connected to processor 401 via a bus. Memory 402 may also be integrated with processor 401.
[0089] The memory 402 stores instructions for executing the scheme of this application, and the processor 401 controls the execution. The processor 401 executes the instructions stored in the memory 402 to realize the functions of the method of this application.
[0090] As an example, combined Figure 5 The functions implemented by the acquisition unit 301 and the processing unit 302 in the data query device 30 are the same as those of the data query device 30. Figure 6 The processor 401 in it has the same function.
[0091] In a specific implementation, as one example, processor 401 may include one or more CPUs, for example... Figure 6 CPU0 and CPU1 in the CPU.
[0092] In a specific implementation, as one example, the electronic device 40 may include multiple processors, such as... Figure 6 Processors 401 and 407 are described in the text. Each of these processors may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. A processor here may refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).
[0093] In a specific implementation, as one embodiment, the electronic device 40 may further include an output device 405 and an input device 406. The output device 405 communicates with the processor 401 and can display information in various ways. For example, the output device 405 may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device 406 communicates with the processor 401 and can acquire input from user objects in various ways. For example, the input device 406 may be a mouse, keyboard, touchscreen device, or sensing device, etc.
[0094] Those skilled in the art will understand that Figure 6 The structure shown does not constitute a limitation on the electronic device 40, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0095] In addition, this application also provides a computer-readable storage medium that, when the instructions in the computer-readable storage medium are executed by the processor of an electronic device, enables the electronic device to perform the data query method provided in the above embodiments.
[0096] In addition, this application also provides a computer program product, including computer instructions, which, when executed on an electronic device, cause the electronic device to perform the data query method provided in the above embodiments.
[0097] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention described herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not invented herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the claims.
Claims
1. A data query method, characterized in that, The method includes: Obtain the AOP aspect information corresponding to the distributed document storage database MongoDB; the AOP aspect information is used to indicate whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries; The step of obtaining the AOP aspect information corresponding to the distributed document storage database MongoDB includes: Based on the attribute information corresponding to each data class, determine whether each data class supports pagination queries; Identify the fields for each data class and set field identifiers for each field; for any given field, if the field identifier is a target identifier, determine that the field supports pagination queries; if the field identifier is not a target identifier, determine that the field does not support pagination queries. And based on whether the value corresponding to each field is empty, determine whether the value corresponding to each field supports pagination query, and obtain the AOP aspect information; Receive a query request; the query request includes the query content and the query permission identifier; When the query permission identifier is a preset identifier, based on the query content and the AOP aspect information, the field names and field values in the query content are dynamically obtained using Java reflection technology, pagination query conditions are assembled, and a query is performed from the MongoDB to obtain the query results; the query results include data that matches the query content and supports pagination query.
2. The method according to claim 1, characterized in that, The receiving of query requests includes: Initial query requests are received via a web portal. The web entry point is marked to add a preset query permission identifier to the initial query request through the web entry point, thus obtaining the query request; the query permission identifier is used to reflect whether the initial query request through the web entry point has permission to access the MongoDB.
3. A data query device, characterized in that, The device includes an acquisition unit, a receiving unit, and a processing unit; The acquisition unit is used to acquire AOP aspect information corresponding to the distributed document storage database MongoDB; the AOP aspect information is used to indicate whether each data class in MongoDB supports paginated queries, whether the fields of each data class support paginated queries, and whether the values corresponding to each field support paginated queries. The acquisition unit is specifically used for: determining whether each data class supports pagination query based on the attribute information corresponding to each data class; determining the fields of each data class and setting field identifiers for each field; for any field, if the field identifier is a target identifier, determining that the field supports pagination query, and if the field identifier is not a target identifier, determining that the field does not support pagination query. And based on whether the value corresponding to each field is empty, determine whether the value corresponding to each field supports pagination query, and obtain the AOP aspect information; The receiving unit is used to receive a query request, which includes query content and query permission identifier; The processing unit is configured to, when the query permission identifier is a preset identifier, dynamically obtain the field names and field values in the query content using Java reflection technology based on the query content and the AOP aspect information, assemble pagination query conditions, perform a query from the MongoDB, and obtain query results; the query results include data that matches the query content and supports pagination queries.
4. The apparatus according to claim 3, characterized in that, The receiving unit, specifically used for receiving query requests, is configured to: Initial query requests are received via a web portal. The web entry point is marked, and a preset query permission identifier is added to the initial query request through the web entry point to obtain the query request; The query permission identifier is used to reflect whether the initial query request through the web portal has permission to access the MongoDB.
5. An electronic device, characterized in that, include: A processor and a memory for storing instructions executable by the processor; wherein the processor is configured to execute instructions to implement the data query method according to any one of claims 1-2.
6. A computer-readable storage medium storing instructions thereon, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is able to perform the data query method as described in any one of claims 1-2.
Citation Information
Patent Citations
Database query method and device
CN112835930A
