如何访问和更改集合中的特定属性?
我有一个名为产品"的收藏集.我想访问并更改集合中一个名为"screenShots"的属性.
I have a collection called "Products". I want to access and change an attribute called "screenShots" inside the collection.
此代码不适用于我
screenshotsURLS: function(sshots) {
check(sshots, [String]);
Products.update({},{$set:{screenShots:sshots}});
console.log(sshots);
}
当我用console.log记录时,我可以看到该数组存在,但是更新功能不起作用
when i console.log the sshots, i can see that the array exists, but the update function isn't working
如何将产品"集合中的screenShots属性设置为"screenshotsURLS"函数中传递的任何值?
how do i set the screenShots attribute inside the Product collection to whatever value passed in "screenshotsURLS" function?
为此,您必须更新mongodb文档.
For that you have to update the mongodb document.
这是在流星中更新文档的方式.
THis is how you can update the doc in meteor.
collectionName.update(
<query>,
<update>,
{
upsert: <boolean>,
multi: <boolean>,
writeConcern: <document>
}
)
在您的情况下,collectionName是Products,字段是screenShots. 因此,这样做.您的查询将是 冲刺
In your your case collectionName is Products and field is screenShots. So for doing this. Your query will be sshots
Products.update({},{$set:{screenShots:sshots}}) (Be careful this will update all of your doc)
要选择文档更新,请使用类似的查询.
For selecting doc update use the query like.
Products.update({name:'yourProductName'},{$set:{screenShots:sshots}})
有关更新的更多信息,请检查此链接
For more about update a please check this link.