【发布时间】:2017-08-21 12:49:36
【问题描述】:
嗨, 我不知道如何给它起一个好的标题,但我相信你会理解的
所以我试图在我的 Mongo 集合上设置 2 个字段,当用户点击一个按钮但每 60sc 时我有一个正在运行的方法,并且是谁做的:
upsertCollectionMachines = Meteor.bindEnvironment(function() {
machinesCount = 0;
var protocol;
var port;
Machine.list({
inspect: true
}, Meteor.bindEnvironment(function(err, machines) {
if (typeof machines === "undefined") {
console.error("Impossible to access 'machines' from 'Machine.list: '" + err);
} else {
machines.forEach(Meteor.bindEnvironment(function(machineInfo) {
machinesCount += 1;
if (machineInfo.url != null) {
var urlToArray = machineInfo.url.split(":")
port = urlToArray[urlToArray.length - 1];
protocol = "https";
} else {
port = "2376";
protocol = "https";
}
InfosMachines.upsert({
nameMachine: machineInfo.name,
}, {
nameMachine: machineInfo.name,
stateMachine: machineInfo.state,
ipAddr: machineInfo.driver.ipAddress,
port: port,
protocol: protocol
//here I want to add isUsed: false,
//whoUseIt: "", but I think if I set isUsed true --> after 60s it will be false again right ?
});
}));
if (apiKeyGenerated == false) {
getTheAPIKeyGrafana(function(err, res) {
if (!err) {
apiKeyGenerated = true;
updateDashboard();
} else {
console.error(err);
}
});
}else{
updateDashboard();
}
}
}));
})
重要的部分是InfosMachines.upsert()。现在我想设置 2 个这样的字段:
'lockTheMachine': function(nameMachine, nameUser){
InfosMachines.upsert({
nameMachine: nameMachine,
}, {
nameMachine: nameMachine,
isUsed: true,
whoUseIt: nameUser
});
//upsertCollectionMachines();
console.log(nameUser +" has locked the machine: " + nameMachine);
},
但首先它看起来不像将 2fields 添加到集合中,其次 60s 间隔方法会删除它们对吗?
感谢您的帮助
【问题讨论】:
-
我有一个想法,我会打开这个帖子,但我的想法是为二手机器创建第二个集合
-
嗨杰罗姆;当您说它看起来不像添加 2 个字段时,您能否准确说明您对数据的预期结果以及实际更新的内容?
-
@VinceBowdren 我明天做,我戳你
标签: javascript mongodb meteor collections