Home:ALL Converter>How to insert document or fields in nested documents in mongo

How to insert document or fields in nested documents in mongo

Ask Time:2016-11-23T15:40:57         Author:user7064075

Json Formatter

I want collection named systems under which there is a document named sub_systems and under which there are three documents named high mid & low. And each high, mid and low contains separate multiple documents Like below

systems: {
           sub_system_1 : {
                            high :{ {task1},
                                    {task2},
                                    .......
                                  },                                
                            mid  :{ {task1},
                                    {task2},
                                    .......
                                  },
                            low :{ {task1},
                                    {task2},
                                    .......
                                  },
                          },
           sub_system_2 : {
                            high :{ {task1},
                                    {task2},
                                    .......
                                  },                                
                            mid  :{ {task1},
                                    {task2},
                                    .......
                                  },
                            low :{ {task1},
                                    {task2},
                                    .......
                                  },
                          },
           ............
         }

So following are the questions I'm having 1. How will I create such nested document. 2. How will I insert new sub_system in the systems collection. 3. How will I insert new priority (high, mid, low) under sub_system document. 4. How will I insert new task in a specific sub_system and under a specific priority(high,low, mid) document

I want to know this using mongo shell and also with perl mongodb

Author:user7064075,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40758606/how-to-insert-document-or-fields-in-nested-documents-in-mongo
yy