我有一个复杂的数据结构是由多个集合上的查询构建并发布的。
它对于初始创建非常有用,并且在我的本地计算机上,观察到的所有更改都会按预期反映在客户端中。但是,在我的暂存环境中,当观察到更改时,我从mini-mongo中收到以下错误
未捕获错误:替换文档时,字段名称可能不包含'。'(...)
发布代码如下所示,其中pub
是this
中的Meteor.publish
而rootObj
是对对象的引用内存,它修改了属性,但从未将它的引用归咎于它。
function _republish(pub, rootId, rootObj, handles, startup) {
// cleanup handles
if (handles.foo) {
handles.foo.stop();
}
// some query which could depend on rootObj/other calculated values
let cursor = SubColl.find({_id: {$in: bar}});
handles.foo = cursor.observeChanges({
removed(_id) {
rootObj.bar = rootObj.bar.filter(o => o._id !== _id);
pub.changed('foobarbaz', rootId, {bar: rootObj.bar})
},
changed(_id, fields) {
const index = rootObj.bar.findIndex(line => line._id === _id);
const changed = {};
_.each(fields, (value, field) => {
rootObj.bar[index][field] = value;
changed[`bar.${index}.${field}`] = value;
});
pub.changed('foobarbaz', rootId, changed);
},
added(_id, fields) {
rootObj.bar.push(_.extend({}, fields, {_id}));
if (!startup) {
// deeper children stuff
pub.changed('foobarbaz', rootId, {bar: rootObj.bar});
}
}
});
// deeper children stuff
startup = false;
// if startup was true, expect caller to publish this
}
正如我们所看到的,当我pub.changed
bar
bar.0.prop
时,发布工作正常,但尝试更新特定的子文档字段(例如bar
)导致行为不一致
如果可能的话,我希望避免重新发布整个import random
import sys
import os
print ("what is the password ?")
instructions = ['-Press [W] To Walk Forward (-Hold [Left Shift] To Initiate Runing)','-Press [S] To Move Backwards' '-[A] For Left','-[D] For Right','-[space] For Jump']
password = sys.stdin.readline()
if password =='food':
print ("here" )
for i in instructions:
print (i)
else:
print ("not correct")
,因为与更新简单属性相比,它是巨大的。
如何将更改发布到子文档的单个字段?