简体   繁体   中英

How to update nested array in mongodb+php?

[Details] => Array
        (
            [0] => Array
                (
                    [Items] => Array
                        (
                            [0] => Array
                                (
                                    [Description] => Discriptionqwe
                                    [Quantity] => qwewe
                                    [ItemName] => not_available
                                    [CategoryName] => health
                                    [ItemsId] => 568e70d66734c482495fb085
                                )

                        )

                    [Distance] => 56.8KM
                    [VendorId] => 5683ad876734c4e2158b4570
                    [Rating] => 0
                    [OpeningTime] => 10AM to 11PM
                    [VendorName] => bombay ji
                )

        )

Try it like this:

var update =  db.collection.update(
                                    { _id:ObjectId("id_of_record")},
                                    { $set: { "Details.$.Items.$.Description":"Discriptionqwe" } }
                            );

    var is_row_affected = db.runCommand({getLastError : 1});                                

    if(is_row_affected['updatedExisting'] == true){  
         result = {msg: '1', data: []};
    }else {
         result = { msg: '0', data: []};
    }
    return result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM