如何访问和更改集合中的特定属性? [英] How to access and change a specific attribute in a collection?

查看:142
本文介绍了如何访问和更改集合中的特定属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为产品"的收藏集.我想访问并更改集合中一个名为"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.

这篇关于如何访问和更改集合中的特定属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆