更新或替换mongoose嵌套数组对象

时间:2014-08-18 14:30:21

标签: mongodb mongoose

我有一个时间表模式,其结果如下所示,我想用mongoose中的一组新值替换单个数据数组对象。要么我想删除已经存在的对象并推送一组新值或用新值更新旧对象。请建议我一个正确的方法来实现这一点。我为此做了很多努力,因为我是mongoose和mongodb的新手。提前致谢

{
    "_id": ObjectId("53f1fb3401ea96440d62646b"),
    "user_id": "andrew",
    "type": "Solutions",
    "timesheets": [{
            "weekStartDate": ISODate("2014-08-18T00:00:00Z"),
            "weekEndDate": ISODate("2014-08-22T00:00:00Z"),
            "_id": ObjectId("53f1fb3401ea96440d62646c"),
            "data": [{
                    "date": ISODate("2014-08-18T00:00:00Z"),
                    "_id": ObjectId("53f1fb3401ea96440d62646d"),
                    "record": [{
                            "_id": ObjectId("53f1fb3401ea96440d626470"),
                            "desc": "",
                            "cellId": "0:0",
                            "custName": "Coach",
                            "custID": "2",
                            "timeSpend": "04:00",
                            "categoryName": "Billing",
                            "categoryID": "1"
                    }, {
                            "_id": ObjectId("53f1fb3401ea96440d62646f"),
                            "desc": "Description",
                            "cellId": "0:1",
                            "custName": "",
                            "custID": "",
                            "timeSpend": "05:00",
                            "categoryName": "Solution",
                            "categoryID": "4"
                    }, {
                            "_id": ObjectId("53f1fb3401ea96440d62646e"),
                            "desc": "Description",
                            "cellId": "0:2",
                            "custName": "",
                            "custID": "",
                            "timeSpend": "06:00",
                            "categoryName": "GTM",
                            "categoryID": "3"
                    }],
                    "savedFlag": false,
                    "submitFlag": false
            }, {
                    "date": ISODate("2014-08-19T00:00:00Z"),
                    "_id": ObjectId("53f1fb4e01ea96440d626471"),
                    "record": [{
                            "_id": ObjectId("53f1fb4e01ea96440d626474"),
                            "desc": "",
                            "cellId": "1:0",
                            "custName": "Morgan",
                            "custID": "3",
                            "timeSpend": "04:00",
                            "categoryName": "RFP",
                            "categoryID": "2"
                    }, {
                            "_id": ObjectId("53f1fb4e01ea96440d626473"),
                            "desc": "",
                            "cellId": "1:1",
                            "custName": "Morgan",
                            "custID": "3",
                            "timeSpend": "05:00",
                            "categoryName": "RFP",
                            "categoryID": "2"
                    }, {
                            "_id": ObjectId("53f1fb4e01ea96440d626472"),
                            "desc": "",
                            "cellId": "1:2",
                            "custName": "Citi",
                            "custID": "1",
                            "timeSpend": "04:00",
                            "categoryName": "Sales",
                            "categoryID": "0"
                    }],
                    "savedFlag": false,
                    "submitFlag": false
            }],
            "savedFlag": true,
            "submitFlag": false
    }],
    "__v": 0

}>

0 个答案:

没有答案