使用 kubernetes 作业运行 mongo shell 脚本
我需要创建将在 mongo shell 上运行以下脚本的 kubernetes 作业:
var operations = [];
db.product.find().forEach(function(doc) {
var documentLink = doc.documentLink;
var operation = { updateMany :{
"filter" : {"_id" : doc._id},
"update" : {$set:{"documentLinkMap.en":documentLink,"documentLinkMap.de":""},
$unset: {documentLink:"","descriptionMap.tr":"","news.tr":"","descriptionInternal.tr":"","salesDescription.tr":"","salesInternal.tr":"","deliveryDescription.tr":"","deliveryInternal.tr":"","productRoadMapDescription.tr":"","productRoadMapInternal.tr":"","technicalsAndIntegration.tr":"","technicalsAndIntegrationInternal.tr":"","versions.$[].descriptionMap.tr":"","versions.$[].releaseNoteMap.tr":"","versions.$[].artifacts.$[].descriptionMap.tr":"","versions.$[].artifacts.$[].artifactNotes.tr":""}}}};
operations.push(operation);
});
operations.push( {
ordered: true,
writeConcern: { w: "majority", wtimeout: 5000 }
});
db.product.bulkWrite(operations);
我需要该作业的示例。我应该创建持久卷并声明其所有权,还是可以在没有持久卷的情况下运行此作业?我需要运行一次然后将其删除。
I need to create kubernetes job that will run below script on mongo shell:
var operations = [];
db.product.find().forEach(function(doc) {
var documentLink = doc.documentLink;
var operation = { updateMany :{
"filter" : {"_id" : doc._id},
"update" : {$set:{"documentLinkMap.en":documentLink,"documentLinkMap.de":""},
$unset: {documentLink:"","descriptionMap.tr":"","news.tr":"","descriptionInternal.tr":"","salesDescription.tr":"","salesInternal.tr":"","deliveryDescription.tr":"","deliveryInternal.tr":"","productRoadMapDescription.tr":"","productRoadMapInternal.tr":"","technicalsAndIntegration.tr":"","technicalsAndIntegrationInternal.tr":"","versions.$[].descriptionMap.tr":"","versions.$[].releaseNoteMap.tr":"","versions.$[].artifacts.$[].descriptionMap.tr":"","versions.$[].artifacts.$[].artifactNotes.tr":""}}}};
operations.push(operation);
});
operations.push( {
ordered: true,
writeConcern: { w: "majority", wtimeout: 5000 }
});
db.product.bulkWrite(operations);
I will need a sample of how that job will look like. Should I create presistent volume and claim to it or is there possibility to run this job without persistent volume? I need to run this once and then remove it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
configMap
,然后将
configMap
安装为将在文件中解析的卷。下面是如何继续操作的示例(注意!您需要为其使用正确的图像以及 mongo shell 工作方式的一些其他更改):
从文件创建一个
configMap
。可以通过运行以下命令来完成:您可以通过运行以下命令来检查您的文件是否存储在其中:
从 configmap 创建一个带有卷挂载的作业 (规范模板与 pod 中使用的相同):
检查它在 Pod 内部的外观
连接到 Pod:
检查文件已显示:
<前><代码># ls /opt
mongoscript.js
检查其内容:
You can solve it much easier with
configMap
and then mount theconfigMap
as a volume which will be resolved in a file.Below is example how to proceed with it (Note! You will need to use a proper image for it as well as some other changes how mongo shell works):
Create a
configMap
from file. Can be done by running this command:You can check that you file is stored inside by running:
Create a job with volume mount from configmap (spec template is the same as it used in pods):
Checking how it looks inside the pod
Connect to the pod:
Check file is presented:
Check its content: