Meteor Mongo更新($ set object; $ push array)

时间:2018-05-04 17:56:52

标签: mongodb meteor mongodb-query

美好的一天。

我很难搞清楚为什么我的mongo没有更新。对象和数组未更新。我有 一直在尝试很多途径。除了下面的代码,我已经尝试在文档中已经有了密钥(但是空了,所以 数组将是keyName:{},以及不在文档中的键。我也尝试将键放在引号等内。 我已经获取了更新的控制台输出并粘贴到Robo3T并运行查询并且它更新了文档。

流星1.6
mongo 3.2.15

运行服务器代码

  const dbQuery = {owner: uid.user_id, paymentToken: uid.paymtToken}
  exFile = {
    $set: {
      agreement_id: responseData.id,              // string
      selfUrl: responseData.links[0].href,          // string
      agreementDetails: responseData.agreement_details, // object
      membershipLevel: 'premium',                // string
      ppOwnerInfo: responseData.payer,            // object
    },
  };
  let subsReturn = MonthlySubs.update(dbQuery, exFile, {multi:false, upsert:false} );
  console.log('subsReturn: ', subsReturn); // outputs: 1

这将导致文档使用除对象之外的所有内容进行更新。我知道exFile有效:

  console.dir(exFile, {depth: null});

结果:

{ '$set':
{ agreement_id: 'I-SW0AL8YJS',
      selfUrl: 'https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-SW0AL',
      agreementDetails:
       { outstanding_balance: { value: '0.00' },
         cycles_remaining: '1',
         cycles_completed: '0',
         next_billing_date: '2018-05-05T10:00:00Z',
         final_payment_date: '1970-01-01T00:00:00Z',
         failed_payment_count: '0' },
      membershipLevel: 'premium',
      ppOwnerInfo:
       { payment_method: 'paypal',
         status: 'verified',
         payer_info:
          { email: 'paypal-buyer@tion.com',
            first_name: 'test',
            last_name: 'buyer',
            payer_id: '99CEFGB6L',
            shipping_address:
             { recipient_name: 'test buyer',
               line1: '1 Main St',
               city: 'San Jose',
               state: 'CA',
               postal_code: '95131',
               country_code: 'US' } } } } }

还有更新阵列的问题。

  let pushFile = {
    $push: {
      links: {href: responseData.links[0].href, rel: 'self', method: 'GET', }
    }
  };
  console.dir(pushFile, {depth: null});
  subsReturn = MonthlySubs.update(dbQuery, pushFile, {multi:false, upsert:false} );
  console.log('subsReturn: ', subsReturn); // outputs: 1

以下是控制台输出中的pushFile内容:

{'$ push':     {链接:        {href:'https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-S45A17AV',          rel:'self',          方法:'GET'}}}

这在Robo3T中也很有效。

我正在使用simpl-schema

[snip]
  selfUrl: {
    type: String,
    label: 'Link for details about subscription on Paypal.',
optional: true,
  },
  ppOwnerInfo: {
    type: Object,
    label: 'Subscriber name, address, etc. from Paypal. Populates after subscription executed. (payer)',
    optional: true,
  },
  links: {
    type: Array,
    label: 'Holds various Paypal endpoints. Optional because not all inserts/updates have these.',
    optional: true,
  },
[/snip]

1 个答案:

答案 0 :(得分:0)

在您的架构中,您需要为blackbox: true设置ppOwnerInfo。也可以agreementDetails查看docs