【巨杉数据库Sequoiadb】如何互相转换DateTime和TimeStamp类型

记录中分别包含 DateTime TimeStamp 两种数据 型, 两种 型如何互相 转换  

【解决 法】
【方法 1 】批量 转换 使用 出工具,操作方法如下:
1.
使用 sdbexprt 导出工具指定匹配条件,导出指定字段类型的记录
  
a 字段 date 的完整 记录
  ./sdbexprt -c foo -l bar --type csv --fields a,b,c,d --filter '{a:{$type:1,$et:9}}' --file foo.bar.csv
2.
删除集合中已导出的记录
  
除如上示例 a 字段 Date 记录
  db.foo.bar.remove({a:{$type:1,$et:9}})
3.
使用 sdbimprt 导入工具指定导入 a 字段 timestamp
  
入上述示例中 a 字段:
  ./sdbimprt -c foo -l bar --fields 'a timestamp' --type csv --file foo.bar.csv
风险
导出记录是需要导出所有字段,否则导出后的记录可能不是完整记录,删除导出的记录再导入后部分记录可能缺少未被导出的字段;
【建
份所有 记录 行如上 出操作,如使用 出工具 份恢复所有数据
1.
导出所有记录
./sdbexprt -c foo -l bar --type json --file foo.bar.allRecords.json
2.
需要恢复原始数据 ,使用 入工具恢复所有 记录
./sdbimprt -c foo -l bar --type json --file foo.bar.allRecords.json
料参考】
导出工具: http://doc.sequoiadb.com/cn/sequoiadb-cat_id-1479195621-edition_id-0
导入工具: http://doc.sequoiadb.com/cn/sequoiadb-cat_id-1479195620-edition_id-0
$type
匹配符: http://doc.sequoiadb.com/cn/SequoiaDB-cat_id-1477878020-edition_id-302

【方法 2 / 少量数据 Date 转换为 Timestamp ,如果更新后的 不同可以使用 update 更新 记录
束】
更新前后 时间 update 更新 时认为值 不需要更新,如 {$date:"2019-01-01"} 更新 {$timestamp:"2019-01-01-00.00.00.000000"} ,如果更新 {$timestamp:"2019-01-01-00.00.00.000001"} 则可以更新
景在后 版本会 化(可能 3.2 以后版本),如果 样则 可以指定参数 制更新。
update 更新】
匹配 a 字段 date 的所有 记录 ,遍 每一条 记录 取原始 记录 a 字段的 ,更新 a 字段 timestamp a 字段的 值为 原始 拼接后的 timestamp 格式的 ,如:
var cursor = db.foo.bar.find({a:{$type:1,$et:9}}); while(records = cursor.next()){ var aVal = records.toObj().a.$date; db.foo.bar.update({$set:{$timestamp: aVal + "-00.00.00.000001"}}, {a:{$date: aVal }})}
料操作】
update
更新: http://doc.sequoiadb.com/cn/sequoiadb-cat_id-1432190847-edition_id-302
$type
匹配符: http://doc.sequoiadb.com/cn/SequoiaDB-cat_id-1477878020-edition_id-302  

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69935160/viewspace-2652040/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/69935160/viewspace-2652040/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值