gpt4 book ai didi

meteor - 重叠订阅不发布所有字段

转载 作者:行者123 更新时间:2023-12-01 14:38:33 26 4
gpt4 key购买 nike

当我有两个限制要发布的字段的订阅时,它不会在两者之间进行联合

这应该只发布头像。

Meteor.publish('userStatisticsByYear', function(year) {
check(year, Number);
this.unblock();

var userStats = UserStatistics.find({year: year},{sort: {count: -1}, limit: 5});
var userIds = userStats.map(function(u) {
return u.userId;
});

return [
Meteor.users.find({_id: {$in: userIds}},{fields: {username: 1, "profile.avatar": 1}}),
ProfileImages.find({owner: {$in: userIds}}),
userStats
];
});

并且此订阅发布了配置文件的更多详细信息。这在某些路线下很好。

Meteor.publish('getUserProfile', function(userId) {
this.unblock();

if (!this.userId) {
this.ready();
return;
}

return [
Meteor.users.find({_id: userId}, {fields: {profile: 1}}),
ProfileImages.find({owner: userId})
]
});

问题是,如果我同时订阅两者,则只会发布“profile.avatar”。但不是来自“getUserProfile”的额外字段

控制台的输出:

Meteor.subscribe('userStatisticsByYear')
Object {subscriptionId: "aQFv4HkGDKx54gJLq"}

Meteor.users.findOne("KABEf7SzNCmQapXND").profile
Object {avatar: "NQokwm9bHgfrMtKLY"}

Meteor.subscribe('getUserProfile','KABEf7SzNCmQapXND')
Object {subscriptionId: "hemH2NF88vwd3AkHv"}

Meteor.users.findOne("KABEf7SzNCmQapXND").profile
Object {avatar: "NQokwm9bHgfrMtKLY"}

最佳答案

我以前见过这个。

如果您使用 Meteor.users.find({"_id":"KABEf7SzNCmQapXND"}).profile 而不是 findOne,我相信它应该可以工作。

关于meteor - 重叠订阅不发布所有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35433585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com