Inserting a dictionary with another nested dictionary into mongoDB using Flask?

Viewed 92

I'm iterating through html form values and creating a dictionary to insert in mongoDB. The code for this is:

# get Venue data

        venue_keys = request.form.getlist('venue_key')
        venue_values = request.form.getlist('venue_data')
        pair_vals = zip(venue_keys, venue_values)
        venue_dict = dict(pair_vals)

I'm separately collecting address details in the same way, using the same code, as shown below:

# get Address data
        address_keys = request.form.getlist('address_key')
        address_values = request.form.getlist('venue_address')
        pair_add_vals = zip(address_keys, address_values)
        address_dict = dict(pair_add_vals)

But how do I nest the Address data into the Venue data dictionary? Using mongo.bla.insert(venue_dict, address_dict) obviously just created two different entries.

To be clear, I need it to go into the database like this:

venue = {
'venue name': Example venue,
'phone number': 012345667889,
'address': { 

    street address 1: 10 example street, 
    town: London, 
    postcode: CB5 8TG

    },

'contact name': Mr Ted Example,
}
0 Answers
Related