【问题标题】:Meteor - Updating user profile inside callbackMeteor - 在回调中更新用户配置文件
【发布时间】:2017-09-12 00:16:20
【问题描述】:

我正在尝试在回调中更新用户配置文件,但我不断收到相同的错误。已经尝试了多种方法..任何帮助都会很棒。谢谢!

异步函数回调中的异常:错误:无效的修饰符。 修饰符必须是一个对象。

        let user = Meteor.users.findOne({"profile.wallets.address": d.Address});
        let wallets = user.profile.wallets;
        wallets[0].amount = d.Amount;

        Meteor.users.update(user._id, {$set: {'profile.wallets': wallets}});

【问题讨论】:

  • 我认为你需要在"$set"周围加上引号
  • 仍然有相同的错误消息@Mikkel
  • 键不需要引号,除非它们是嵌套的。 $set$inc 等运算符不需要引用。
  • 我建议在调试器中执行 `console.log({$set: {'profile.wallets': wallets}}) 以确保表达式实际生成对象。确实应该,但那是修饰符。

标签: meteor meteor-accounts


【解决方案1】:

您是否尝试过这样做:

let profile = user.profile
profile.wallets = wallets
Meteor.users.update(user._id, {$set: {profile: profile}})

因为也许修饰符不能是虚线路径

【讨论】:

  • 如果引用,键名可以包含虚线路径。这里还有其他事情发生。
猜你喜欢
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
  • 2022-01-03
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 2017-05-19
  • 2018-09-11
相关资源
最近更新 更多