如何将我的数据插入到 mongoDB 循环中的集合中?
我想将数据填充到 mongo db 中的集合中。如果我对插入查询进行硬编码,那就好像:
db.devices.insertMany([
{"_id" : "FX200FTQ2109BZ00", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
{"_id" : "FX200FTQ2109BZ01", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
{"_id" : "FX200FTQ2109BZ02", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
...
{"_id" : "FX200FTQ2109BZ0A", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
...
{"_id" : "FX200FTQ2109BZ0Z", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" }
]);
正如我们所看到的,“_id”值的最后一个字符在(0~9,A~Z)范围内。那么有没有一种循环方式可以将此类数据填充到 MongoDB Shell 中?
谢谢,
杰克
I want to populate data into a collection in mongo db. If I to hard-code the insert query, it would be as if:
db.devices.insertMany([
{"_id" : "FX200FTQ2109BZ00", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
{"_id" : "FX200FTQ2109BZ01", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
{"_id" : "FX200FTQ2109BZ02", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
...
{"_id" : "FX200FTQ2109BZ0A", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" },
...
{"_id" : "FX200FTQ2109BZ0Z", "cloud_blueprint_id" : 105969, "cloud_blueprint_name" : "AWS-BP" }
]);
As we can see, the last char of "_id" value is in the range of (0~9,A~Z). So is there a loop way I can have such data populated inside MongoDB Shell ?
Thanks,
Jack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
瞧:
解释:
当然,您可以修改和创建更大的批次,其中包含 insertMany 中的多个条目,
这里是 insertMany 选项:
Voila:
Explained:
Afcourse you can modify and create bigger batches with multiple entries inside insertMany
here is the insertMany option: