将当前用户的 ID 推送到 meteorjs 中集合/文档的内部数组
Push currentUser's ID to inner Array of a collection/ document in meteorjs
{
"_id" : "s2QBCnv6fXv5YbjAP",
"question" : "Is this real change?",
"createdAt" : ISODate("2016-05-13T21:05:23.381Z"),
"yes" : [
{
"heading" : "Yes It is",
"body" : "I think this government knows what they are doing. That's why there has not been any form of protest",
"email" : "I think this government knows what they are doing. That's why there has not been any form of protest",
"createdAt" : ISODate("2016-05-13T21:08:25.119Z"),
"replies" : [ ],
"likes" : [ ]
},
{
"heading" : "Well, Yes",
"body" : "I think this is change as we all want to know what the government is doing and I am grateful to be alive at this time",
"email" : "I think this is change as we all want to know what the government is doing and I am grateful to be alive at this time",
"createdAt" : ISODate("2016-05-13T21:10:47.123Z"),
"replies" : [ ],
"likes" : [ ]
}
],
"no" : [
{
"heading" : "Not at All",
"body" : "This is not the change I wanted. This is waste of four years and I amm waiting to see the promised change",
"email" : "kenshin@kay.com",
"createdAt" : ISODate("2016-05-13T21:12:58.977Z"),
"replies" : [ ],
"likes" : [ ]
}
],
"author" : "admin",
"image" : "/cfs/files/QuestionImages/DzdpK6NdurZMTwAse"
}
大家好,我是 MeteorJs 的新手,我正在开发一个应用程序。 我想知道如何更新"喜欢"数组。我想将当前用户的 ID 推送到喜欢中,因此在前端我将显示 yes.objectsReference.likes.length 作为喜欢的数量。
如何定位点赞数组?谢谢
您可以使用服务器上的 $
位置运算符来更新 likes 数组。假设您要将当前用户 ID 添加到嵌入的"是"文档上的 likes 数组中,标题值为"嗯,是",那么下面显示了如何在服务器上执行此操作:
Articles.update(
{
"_id" : "s2QBCnv6fXv5YbjAP",
"yes.heading" : "Well, Yes"
},
{
"$push": { "yes.$.likes": userId }
}
)
相关文章:
- 将当前用户的 ID 推送到 meteorjs 中集合/文档的内部数组
- 如何从游标(集合)中检索n个文档的组
- 将多级 mongodb 文档转换为 Backbone.js 模型/集合
- 如何使用文档的ID从mongoDB集合中删除文档
- 使用 Mongoose 在所有现有集合中查找引用的文档
- MongoDB:如何将这个散列添加到集合中的每个文档中
- Meteor Update集合-未捕获错误:不允许.不受信任的代码只能通过ID更新文档.[403]
- 通过最大的嵌入式文档对文档集合进行排序 mongodb
- MongoDB 遍历文档集合
- 如何使用猫鼬从集合中删除所有文档
- 数组中嵌入文档的集合更新属性
- 在流星集合文档中插入值
- MongoDB在将文档插入数据库之前为空集合
- 获取集合中不符合条件的所有文档
- 无法在node.js中使用MongoClient列出mongodb集合中的文档
- 来自不同集合的子文档 ID 数组的猫鼬架构
- 将特定字段从流星集合文档中检索到JS文件中并去除HTML标签
- 从 Meteor 中的集合文档返回单个值
- MongoDB(通过Meteor)在更新集合文档时将对象属性视为字符串
- JS/MongoDB:检查对象(集合文档)中是否存在嵌套字段