code: def create_new_database(request):
      
      name = "Create a New MongoDB Database"
  
      if request.method == 'POST':
          form = CreateDatabaseForm(request.POST)
  
          if form.is_valid():
              result = form.save()
              if "error" in result:
                  messages.error(
                      request, "The database creation operation failed.")
                  messages.error(request, result["error"])
              else:
                  messages.success(request, "Database created.")
              return HttpResponseRedirect(reverse('djmongo_show_dbs'))
          else:
              # The form is invalid
              messages.error(
                  request, _("Please correct the errors in the form."))
              return render(request,
                            'djmongo/console/generic/bootstrapform.html',
                            {'form': form,
                             'name': name})
  
      else:
          # this is a GET
          context = {'name': name,
                     'form': CreateDatabaseForm(
                         initial={"initial_document": '{ "foo" : "bar" }'
                                  })
                     }
          return render(request, 'djmongo/console/generic/bootstrapform.html',
                        context)
docs: Create a New Mongo Database by adding a single document.