Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert DateTime and TimeStamp types in Sequoiadb

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to convert DateTime and TimeStamp types in Sequoiadb. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

[solution]

[method 1] Import and export tool is recommended for batch conversion, and the operation method is as follows:

1. Use the sdbexprt export tool to specify matching criteria and export records of the specified field type

For example, a complete record with a field type of date is exported:

. / sdbexprt-c foo-l bar-- type csv-- fields a filter'{a: {$type:1,$et:9}}'--file foo.bar.csv

two。 Delete exported records in the collection

For example, delete a record with a field type of Date as shown in the above example

Db.foo.bar.remove ({a: {$type:1,$et:9}})

3. Use the sdbimprt Import tool to specify that the import a field type is timestamp

If you import the a field in the above example:

. / sdbimprt-c foo-l bar-- fields'a timestamp'-- type csv-- file foo.bar.csv

[risk]

To export a record, you need to export all fields, otherwise the exported record may not be a complete record, and some records may lack unexported fields after deleting the exported record and importing it.

[suggestion]

Back up all records before performing import and export operations as above, such as backing up and restoring all data using the import and export tool

1. Export all records

. / sdbexprt-c foo-l bar-- type json-- file foo.bar.allRecords.json

two。 When you need to restore the original data, use the import tool to restore all records

. / sdbimprt-c foo-l bar-- type json-- file foo.bar.allRecords.json

[method 2] A single / small amount of data Date is converted into Timestamp. If the updated values are different, you can use update to update the record.

[constraint]

If the time before and after the update is the same, update thinks that the value does not need to be updated, for example, {$date: "2019-01-01"} is updated to {$timestamp: "2019-01-01-00.00.00.000000"}, and can be updated if it is updated to {$timestamp: "2019-01-01-00.00.000001"}.

This scenario will be optimized in subsequent versions (possibly later than 3.2), and if the values are the same, you can specify parameters to force updates.

[update update]

Match all records with a field type date, iterate through each record, get the value of the original record a field, and update the a field type timestamp,a field value to the timestamp format value after the original value splicing, such as:

Var cursor = db.foo.bar.find ({a: {$type:1,$et:9}}); while (records = cursor.next ()) {var aVal = records.toObj () .a.update; db.foo.bar.update ({$set: {$timestamp: aVal + "- 00.00.000001"}}, {a: {$date: aVal}})}

After reading the above, do you have any further understanding of how to convert DateTime and TimeStamp types in Sequoiadb? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report