【问题标题】:Meteor element in array of a array数组中的流星元素
【发布时间】:2017-03-21 23:02:32
【问题描述】:

基本上想在数组数组中推送数据,即 publicHolidays 是外部数组,holidayList 是内部数组。这是现在看起来的 mongodb 架构。

"publicHolidays" : [
        {
                "location" :"pune"
                "year" : 2016
                "holidayList"[
                        {
                               "holidayDate" :"2016-11-09",
                                "holidayName":"Diwali"

                        }
                ]
        }
]

I am expecting below schema,wanted to push data in holidayList.

"publicHolidays" : [
        {
                "location" :"pune"
                "year" : 2016
                "holidayList"[
                        {
                               "holidayDate" :"2016-11-09",
                                "holidayName":"Diwali"

                        }
                        {
                               "holidayDate" :"2016-1-09",
                                "holidayName":"padwa"

                        }
                        {
                               "holidayDate" :"2016-12-10",
                                "holidayName":"holi"

                        }
                ]
        }
]

【问题讨论】:

  • 你的代码在哪里..?
  • 你在哪里期待这个?在数据库还是什么?

标签: arrays mongodb meteor mongodb-query


【解决方案1】:

已解决的问题:

    //Add Holidays in Exist Location
    'companySettings.updatePublicHolidays'(formValues){
    CompanySettings.update(
        { 
          '_id': formValues.UniqueID,
          'publicHolidays' : {$elemMatch : {'location': formValues.holidaysLocation,'year': formValues.holidayYear} }
        },  
        {
            $push : {'publicHolidays.$.holidayList': 
                        {
                            'holidayDate' : formValues.leaveDate , 
                            'holidayName' : formValues.holidayName
                        }
                    }
        }
    );

},

【讨论】:

    猜你喜欢
    • 2015-06-08
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多