Mongoimport/Mongoexport和时间赛
mongoimport
和 mongoexport
cli 工具是否支持新的时间序列集合类型?
我们正在尝试从时间序列集合中导出数据:
mongoexport -h localhost --port=27018 --type=json --db=tstest -c tsdata
并且出现以下错误:
connected to: mongodb://localhost:27018/
Failed: (CommandNotSupportedOnView) PlanExecutor error during aggregation :: caused by :: Namespace tstest.tsdata is a timeseries collection
要解决该问题,我需要伪造这样的查询语句:
mongoexport -h localhost --port=27018 --type=json --db=tstest -c tsdata -q="{}"
但这让我怀疑该工具有问题。
不仅如此,如果我需要使用 mongoimport
导入 JSON 数据集,我还有另一个问题,对于时间序列集合中的每个导入记录,无法不创建 _id
字段
mongoimport -h localhost --port=27018 --type=json --db=tstest -c tsdata --file=rawdata.json
文件有很多像这样的行
{ "metadata": {"feedId": "fd::6022a06ba3d9e1001969c92f", "assetId": "fd::5fc900afce5a0300198df68a" }, "timestamp": { "$date" : "2022-04-05T10:48:50.908Z" }, "value": 74 }
...
,在我的数据库上,导入后,我所有的时间序列记录都有这种形式,
/* 1 */
{
"timestamp" : ISODate("2022-04-05T10:48:50.908Z"),
"metadata" : {
"assetId" : "fd::5fc900afce5a0300198df68a",
"feedId" : "fd::6022a06ba3d9e1001969c92f"
},
"_id" : ObjectId("624c03ca560bfaa462084f85"),
"value" : 74
}
但我不想在每条记录上都添加额外的数据。 有什么解决办法吗?
我使用的是 mongod 版本 5.0.6。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mongoimport
当前不支持自动创建时间表集合()。您需要先在新群集/实例上运行
createCollection
,然后在现有的时间序列集合中AIMmongoimport
。mongoimport
does not currently support creating a time-series collection automatically (reference).You will need to run
createCollection
on your new cluster/instance first, then aimmongoimport
at the existing time-series collection.