Movatterモバイル変換


[0]ホーム

URL:


CN111782667A - MongoDB updating data driving method, system and storage medium - Google Patents

MongoDB updating data driving method, system and storage medium
Download PDF

Info

Publication number
CN111782667A
CN111782667ACN202010574553.3ACN202010574553ACN111782667ACN 111782667 ACN111782667 ACN 111782667ACN 202010574553 ACN202010574553 ACN 202010574553ACN 111782667 ACN111782667 ACN 111782667A
Authority
CN
China
Prior art keywords
data
module
updating
field
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010574553.3A
Other languages
Chinese (zh)
Other versions
CN111782667B (en
Inventor
赵鹏飞
张建洋
黄松
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu School Spirit Technology Co ltd
Original Assignee
Chengdu School Spirit Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu School Spirit Technology Co ltdfiledCriticalChengdu School Spirit Technology Co ltd
Priority to CN202010574553.3ApriorityCriticalpatent/CN111782667B/en
Publication of CN111782667ApublicationCriticalpatent/CN111782667A/en
Application grantedgrantedCritical
Publication of CN111782667BpublicationCriticalpatent/CN111782667B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

The invention discloses a driving method, a system and a storage medium for MongoDB updated data, wherein the method directly adopts original data in a database in an inquiry stage, so that the memory space is saved; meanwhile, in the MongoDB data updating driving method, the combined statement is directly updated by the native bulk operation in the updating stage, so that the use expense of the cpu is greatly reduced.

Description

MongoDB updating data driving method, system and storage medium
Technical Field
The invention relates to a database technology, in particular to a driving method, a system and a storage medium for MongoDB updated data.
Background
With the popularity of the non-relational database MongoDB in the industry, more and more ODMs such as Morphia, PyMongo, Mongoose also provide gradually sophisticated functionality so that developers can manipulate documents stored in the database as normal objects. Taking Mongoose as an example, when a certain document in a database needs to be updated, a target object is found through a Mongoose query method, because the object inherits a Model class in Mongoose, some operations can be smoothly performed on the object, and then a save method of the object is called to be saved in the database.
While updating data using ODM is straightforward at the code level, these are based on sacrificing performance. Under the scene that a plurality of documents need to be updated, each object has a plurality of instances of Mongoose defaults, so that the memory overhead is obviously increased, when a single document needs to modify data in an embedded array, the Mongoose directly covers the original array with a new array, and when the array is large, the covering write operation brings huge cpu overhead.
Therefore, there is a need to design a data updating scheme suitable for the non-relational database MongoDB and capable of saving the memory and cpu overhead.
Disclosure of Invention
In view of the above-mentioned deficiencies of the prior art, the present invention aims to: the MongoDB updating data driving method can save memory and cpu expenses.
In order to achieve the purpose, the invention provides the following technical scheme:
a driving method of MongoDB updating data comprises the following steps:
s1: inquiring data which needs to be updated into target data in the database at this time, and caching the inquired data into a memory;
s2: checking whether each object in an outermost object array of data in a memory contains a _ id field;
if the _ id field is not included, directly entering step S3; if the data comprise the _ id field, assigning the _ id field, combining statements used for assigning the _ id field, and updating the data needing to be updated in the database according to the statements used for assigning the _ id field to ensure that the data are consistent with the data in the memory;
s3: copying data in a memory, and performing updating operation on one part of data to update the part of data into the target data;
s4: comparing the two data in the memory and combining a statement for updating the database;
s5: and updating corresponding data in the database into the target data according to the statement for updating the database.
According to a specific implementation mode, in the driving method for the MongoDB update data, statements used for updating the database are transmitted into the bulk handle as parameters to be executed, so that corresponding data in the database is updated to be the target data.
According to a specific embodiment, in the driving method for the montgodb update data of the present invention, according to the data type and the operation type of the object, a corresponding operator is selected, and the selected operator is added to the combined statement.
In an aspect of specific implementation, the present invention further provides a driving system for updating data by MongoDB, including:
the memory module is used for caching data;
the query module is used for querying data which needs to be updated into target data in the database at this time, and caching the queried data into the memory module;
a field check module, configured to determine whether each object in an outermost object array of data in the memory module includes a _ id field; if the _ id field is not included, triggering a copying module to work; if the _ id field is contained, sequentially triggering a field assignment module, a statement combination module, a database updating module and a copying module to work;
the copying module is used for copying a copy of data in the memory module according to the triggering of the field checking module and triggering the statement combination module to work;
the field assignment module is used for assigning the value to the _ id field according to the triggering of the field checking module;
the statement combination module is used for combining statements used for assigning values to the _ id fields according to the triggering of the field checking module and combining statements used for updating the database according to the triggering of the copying module;
the data updating module is used for updating a copy of copied data to enable the copy of copied data to be updated into the target data;
and the database updating module is used for updating corresponding data in the database according to the statement used for assigning the value to the _ id field and the statement used for updating the database.
In an aspect of specific implementation, the present invention further provides a readable storage medium, on which one or more programs are stored, and the one or more programs, when executed by one or more processors, implement the driving method of the MongoDB update data of the present invention.
Compared with the prior art, the invention has the beneficial effects that:
in the driving method for MongoDB update data, original data in the database are directly adopted in the query stage, so that the memory space is saved, the data in the database is packaged with a layer of object arrays in the query stage in the prior art for conveniently operating the data, and once the query results are more, a larger memory is occupied; in the driving method for MongoDB updating data, combined statements are directly updated by using the native bulk operation in the updating stage, so that the use expense of the cpu is greatly reduced.
Drawings
FIG. 1 is a flow chart of the method of the present invention;
FIG. 2 is a schematic diagram of the system of the present invention.
Detailed Description
The embodiments of the present invention are described below with reference to specific embodiments, and other advantages and effects of the present invention will be easily understood by those skilled in the art from the disclosure of the present specification. The invention is capable of other and different embodiments and of being practiced or of being carried out in various ways, and its several details are capable of modification in various respects, all without departing from the spirit and scope of the present invention.
As shown in fig. 1, the method for driving the montodb update data according to the present invention includes the following steps:
s1: inquiring data which needs to be updated into target data in the database at this time, and caching the inquired data into a memory;
s2: checking whether each object in an outermost object array of data in a memory contains a _ id field;
if the _ id field is not included, directly entering step S3; if the data comprise the _ id field, assigning the _ id field, combining statements used for assigning the _ id field, and updating the data needing to be updated in the database according to the statements used for assigning the _ id field to ensure that the data are consistent with the data in the memory;
s3: copying data in a memory, and performing updating operation on one part of data to update the part of data into the target data;
s4: comparing the two data in the memory and combining a statement for updating the database;
s5: and updating corresponding data in the database into the target data according to the statement for updating the database.
Specifically, in the method for driving the MongoDB update data, statements for updating the database are used as parameters and are transmitted to the bulk handle for execution, so that corresponding data in the database is updated to the target data.
In the method for driving the MongoDB update data according to the present invention, the corresponding words are combined in the following manner: and selecting a corresponding operator according to the data type and the operation type of the object, and adding the selected operator to the combined statement.
Js is taken as an example, it is set that the original data a1, a2, A3 … in the montodb need to be updated to B1, B2, B3 … according to some rule. Then, the driving method for the montodb update data according to the present invention includes the following steps:
(1) and inquiring data A1, A2 and A3 … which need to be updated to a memory at this time, wherein the data are Object objects corresponding to the JSON format documents in the database.
(2) For each data a1, a2, A3 … in the memory that needs to be updated, the outermost object array, i.e., the first level key and value, respectively, is checked, and the value characterizes the condition of the object array. Specifically, for each object array in the value, if the _ id attribute is not included, the value needs to be assigned with an _ id attribute, the value is the ObjectId in the MongoDB, and the update statement of the _ id is set in combination, and at this time, the data in the memory becomes C1, C2, and C3 ….
(3) The statements with the _ id set in the previous step are used to update the data A1, A2 and A3 … in the database to be consistent with the data C1, C2 and C3 … in the memory, namely, the data in the database is also updated to C1, C2 and C3 … at this time.
(4) Copying data in the memory, and performing an updating operation on the data, and updating one of the data C1, C2 and C3 … into target data B1, B2 and B3 …, so that the memory has two data, namely the data C1, C2 and C3 … before updating and the final data B1, B2 and B3 … after updating.
(5) And comparing the two data in the memory, and combining the update statements of the database.
(6) And updating the database by using the updating statement of the previous step, so that the data C1, C2 and C3 … in the database are also updated to be B1, B2 and B3 ….
In practice, the set _ id attribute operation in step (2) (3) aims to: and (5) providing prompt information when the update statements are combined in the step (5), and when the values of a certain object array of the new data and the old data are compared, the objects in the original database have _ id fields, and the new objects have no _ id fields, so that push operation should be adopted. Since the Javascript has only five data types of String, Number, Boolean, Array and Object, for the value of the Array type, we can update its value using $ push and $ pull operators, and for the other four types we can update its value using $ set and $ unset operators, in the case of two new and old data, we can completely combine the corresponding update statements, so that the old data is updated as new data, and the purpose of step (5) is to obtain such an Array of update statements containing these 4 update operators, which is transmitted as a parameter to the bulk handle for execution, i.e., the update of the data in the database can be completed.
As shown in fig. 2, in an aspect of specific implementation, the present invention further provides a driving system for updating data by MongoDB, including:
the memory module is used for caching data;
the query module is used for querying data which needs to be updated into target data in the database at this time, and caching the queried data into the memory module;
a field check module, configured to determine whether each object in an outermost object array of data in the memory module includes a _ id field; if the _ id field is not included, triggering a copying module to work; if the _ id field is contained, sequentially triggering a field assignment module, a statement combination module, a database updating module and a copying module to work;
the copying module is used for copying a copy of data in the memory module according to the triggering of the field checking module and triggering the statement combination module to work;
the field assignment module is used for assigning the value to the _ id field according to the triggering of the field checking module;
the statement combination module is used for combining statements used for assigning values to the _ id fields according to the triggering of the field checking module and combining statements used for updating the database according to the triggering of the copying module;
the data updating module is used for updating a copy of copied data to enable the copy of copied data to be updated into the target data;
and the database updating module is used for updating corresponding data in the database according to the statement used for assigning the value to the _ id field and the statement used for updating the database.
In an aspect of specific implementation, the present invention further provides a readable storage medium, on which one or more programs are stored, wherein the one or more programs, when executed by one or more processors, implement the driving method of the montgodb update data of the present invention.
It should be understood that the disclosed system may be implemented in other ways. For example, the division of the modules into only one logical function may be implemented in another way, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not implemented. In addition, the communication connection between the modules may be an indirect coupling or communication connection through some interfaces, devices or units, and may be electrical or in other forms.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each module may exist alone physically, or two or more modules are integrated into one processing unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.

Claims (5)

CN202010574553.3A2020-06-222020-06-22MongoDB updated data driving method, system and storage mediumActiveCN111782667B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202010574553.3ACN111782667B (en)2020-06-222020-06-22MongoDB updated data driving method, system and storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202010574553.3ACN111782667B (en)2020-06-222020-06-22MongoDB updated data driving method, system and storage medium

Publications (2)

Publication NumberPublication Date
CN111782667Atrue CN111782667A (en)2020-10-16
CN111782667B CN111782667B (en)2024-05-17

Family

ID=72756103

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202010574553.3AActiveCN111782667B (en)2020-06-222020-06-22MongoDB updated data driving method, system and storage medium

Country Status (1)

CountryLink
CN (1)CN111782667B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101499069A (en)*2008-02-022009-08-05中兴通讯股份有限公司Internal memory database file updating method and apparatus
CN108536798A (en)*2018-04-022018-09-14携程旅游网络技术(上海)有限公司The restoration methods and system of the other database data of order level
CN109597818A (en)*2018-11-282019-04-09优刻得科技股份有限公司Data-updating method, device, storage medium and equipment
CN110795494A (en)*2018-07-172020-02-14北京京东尚科信息技术有限公司Automatic testing method and device for synchronous and asynchronous cache data
CN110874364A (en)*2019-11-192020-03-10北京启迪区块链科技发展有限公司Query statement processing method, device, equipment and storage medium
CN111008244A (en)*2019-11-222020-04-14厦门安胜网络科技有限公司Database synchronization and analysis method and system
CN111143326A (en)*2019-12-262020-05-12深圳前海环融联易信息科技服务有限公司Method and device for reducing database operation, computer equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101499069A (en)*2008-02-022009-08-05中兴通讯股份有限公司Internal memory database file updating method and apparatus
CN108536798A (en)*2018-04-022018-09-14携程旅游网络技术(上海)有限公司The restoration methods and system of the other database data of order level
CN110795494A (en)*2018-07-172020-02-14北京京东尚科信息技术有限公司Automatic testing method and device for synchronous and asynchronous cache data
CN109597818A (en)*2018-11-282019-04-09优刻得科技股份有限公司Data-updating method, device, storage medium and equipment
CN110874364A (en)*2019-11-192020-03-10北京启迪区块链科技发展有限公司Query statement processing method, device, equipment and storage medium
CN111008244A (en)*2019-11-222020-04-14厦门安胜网络科技有限公司Database synchronization and analysis method and system
CN111143326A (en)*2019-12-262020-05-12深圳前海环融联易信息科技服务有限公司Method and device for reducing database operation, computer equipment and storage medium

Also Published As

Publication numberPublication date
CN111782667B (en)2024-05-17

Similar Documents

PublicationPublication DateTitle
US11693912B2 (en)Adapting database queries for data virtualization over combined database stores
US10635666B2 (en)System, method and device for index compilation to optimize index usage
US10678789B2 (en)Batch data query method and apparatus
US11238035B2 (en)Personal information indexing for columnar data storage format
CN113254470B (en) A data modification method, device, computer equipment and storage medium
CN117807091A (en)Data association method and device
CN110928941B (en) A data fragmentation extraction method and device
EP3293645B1 (en)Iterative evaluation of data through simd processor registers
CN115795521A (en) Access control method, device, electronic device and storage medium
CN119201885A (en) Metadata migration method and device between databases, storage medium, and equipment
CN118193032B (en)Method, apparatus, device, medium and program product for eliminating invalid dependency library
CN1050938A (en) Invalid access program for database system
US8286144B2 (en)Administering a process filesystem with respect to program code conversion
CN111782667A (en)MongoDB updating data driving method, system and storage medium
CN114995820B (en)Code translation method, apparatus, device, storage medium, and program product
CN116821180A (en)Control method supporting FlinkSQL data desensitization and electronic equipment
CN115292348A (en)Database processing method and system, electronic equipment and storage medium
CN104715056B (en)A kind of method and apparatus using Lifetime of Web Pages optimization application
CN112506651A (en)Method and equipment for data operation in large-data-volume environment
CN110990648A (en)Virus query method, server and computer readable storage medium
CN110096274A (en)The generation code reuse matching management method of distributed memory columnar database
CN113806504B (en)Multi-dimensional report data calculation method and device and computer equipment
CN102662668B (en)Method and device for optimizing application by utilizing webpage life cycle
US9823841B2 (en)Associating keys with data and compute objects in a storage compute device
CN118796867A (en) A training method and device for an artificial intelligence model of a database

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp