更新MongoDB中的Sub Sub Array项

时间:2018-07-14 11:54:14

标签: node.js mongodb

我正在尝试更新MongoDB中的Sub-Sub Array项。我想更新Slides数组内的Comments(注释字段)。

幻灯片->评论->评论

void test(int ch) { }

下面是示例数据。

var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var AttachmentSchema = new Schema({
   FileName: String,
   InternalName: String,
   FileType: String,
   InternalName: String
 });

mongoose.model('Attachment', AttachmentSchema);

var SessionSchema = new Schema({
SessionTitle: String,
Chairperson: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
StartDateTime: { type: Date, required: true },
Duration: Number,
Attendees: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
AcceptOrReject: {
    Comment: String,
    Reason: String,
    CreatedDate: Date,
    UserId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
    Status: String
},
Slides: [{
    Seq: Number,
    Details: String,
    attachement: AttachmentSchema,
    TarasulLetterDetails:{
        MailObjectId: String,
        Description: String,
        Subject: String,
        TarasulLetterUrl: String
    },
    Comments: [{
        Comment: String,
        DateTime: Date,
        UserId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
        IsFromOnline : String
    }],
    SurfaceAttachement: [{
        FileName: String,
        InternalName: String,
        FileType: String,
    }]
}],
Status: String,
CreatedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
CreatedDate: { type: Date, required: true },
ModifiedDate: Date,
SentDate: Date,
Comments: [{
    Comment: String,
    DateTime: Date,
    UserId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}],
Notifications: [{
    UserId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
    CreatedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
    AlertType: String,
    AlertMessage: String,
    DateTime: { type: Date, required: true },
    IsAcknowledged: Boolean
}]
});
mongoose.model('Session', SessionSchema);

例如,我要更新会话“ _id”:ObjectId(“ 5af7bcdff107cb7a105243f5”) 带有Seq:1的幻灯片和带有“ IsFromOnline”为“ 3043”的“新评论”到“更新评论”的评论。

我在下面尝试了其他方法,但是似乎不起作用。

> db.sessions.find({"_id": ObjectId('5af7bcdff107cb7a105243f5')}).pretty();
  {
    "_id" : ObjectId("5af7bcdff107cb7a105243f5"),
    "SessionTitle" : "Project Status Meeting",
    "Duration" : 60,
    "StartDateTime" : ISODate("2018-05-15T05:15:00Z"),
    "CreatedBy" : ObjectId("5aead4431a7ecc7230fb249a"),
    "Status" : "APPROVED",
    "CreatedDate" : ISODate("2018-05-13T04:19:43.050Z"),
    "Notifications" : [
            {
                    "IsAcknowledged" : false,
                    "DateTime" : ISODate("2018-05-14T09:15:23.385Z"),
                    "AlertMessage" : "Attendee updated",
                    "AlertType" : "Attendee",
                    "UserId" : ObjectId("5aead4a81a7ecc7230fb249c"),
                    "_id" : ObjectId("5af953ab67f3be54d4256f35")
            },
    ],
    "Comments" : [ ],
    "Slides" : [
            {
                    "Seq" : 1,
                    "Details" : "<p>Project Meeting</p>\n",
                    "_id" : ObjectId("5af7bcdff107cb7a105243f6"),
                    "Comments" : [
                            {
                                    "_id" : ObjectId("5b45b854d217f62010fea8e7"),
                                    "DateTime" : ISODate("2018-07-11T07:53:40.967Z"),
 "IsFromOnline" : "3047",
                                    "UserId" : ObjectId("5aead4431a7ecc7230fb249a"),
                                    "Comment" : "test 123"
                            },
                            {
                                    "_id" : ObjectId("5b45b89e7c32803a282e44db"),
                                    "IsFromOnline" : "3043",
                                    "DateTime" : ISODate("2018-07-11T07:58:22.648Z"),
                                    "UserId" : ObjectId("5aead4431a7ecc7230fb249a"),
                                    "Comment" : "new comments"
                            }
                    ]
            },
            {
                    "Details" : "<p>second side</p>\n",
                    "Seq" : 2,
                    "_id" : ObjectId("5af7c843f107cb7a105243f7"),
                    "Comments" : [
                            {
                                    "_id" : ObjectId("5b45b9bc569a4b284074fd08"),
                                    "IsFromOnline" : "92179",
                                    "DateTime" : ISODate("2018-07-11T08:03:01.851Z"),
                                    "UserId" : ObjectId("5aead4431a7ecc7230fb249a"),
                                    "Comment" : "test comments 123434343434343"
                            }
                    ]
            }
    ],
    "Attendees" : [
            ObjectId("5aead4a81a7ecc7230fb249c")
    ],
    "Chairperson" : [
            ObjectId("5aead4701a7ecc7230fb249b")
    ],
    "__v" : 0,
    "AcceptOrReject" : [
            {
                    "Reason" : "More changes neened",
                    "Status" : "APPROVED",
                    "UserId" : ObjectId("5aead4701a7ecc7230fb249b"),
                    "CreatedDate" : ISODate("2018-05-14T09:15:23.385Z"),
                    "Comment" : "Will disucuss in next meeting"
            }
    ]
 }

0 个答案:

没有答案