title: How to take the value of a specific key in MongoDB with Python
body: <p>I'm sure this is simple, but I need to pull a value from a key-value pair to check if it matches the username in session. (I'm using pymongo)</p>
  
  <p>An example of one of the MongoDB object looks like this ('jam_or_event' is the collection name):</p>
  
  <pre><code>_id: ObjectId("5d44545037b30613b88ae587")
  jam_title: "Test Jam 2"
  genre: "Rock"
  date_of_jam: "2 August, 2019"
  jam_location: "Test Address 2"
  jam_county: "Bristol"
  jam_member_1: "TestUser2"
  member_instrument_1: "Drums"
  jam_notes: "Test 2"
  jam_owner: "TestUser2"
  </code></pre>
  
  <p>The values change object to object, but I want to be able to pull the jam_owner value from the currently selected object, and ask if it's the same a the username of the user currently logged in. If they match, they'll have more privileges over the page.</p>
  
  <p>Here's the code for the python function:</p>
  
  <pre><code>@app.route('/edit_jam/&lt;jam_id&gt;', methods=['POST', 'GET'])
  def edit_jam(jam_id):
      user_logged_in = 'username' in session
      the_jam =  mongo.db.jam_or_event.find_one({"_id": ObjectId(jam_id)})
      username=session['username']
  
      if request.method == 'POST':
          if user_logged_in:
              jams = mongo.db.jam_or_event
              jams.update( {'_id': ObjectId(jam_id)},
              {
                  'jam_title':request.form.get('jam_title'),
                  'genre':request.form.get('genre'),
                  'date_of_jam': request.form.get('date_of_jam'),
                  'jam_location': request.form.get('jam_location'),
                  'jam_county':request.form.get('jam_county'),
                  'jam_member_1':request.form.get('jam_member_1'),
                  'member_instrument_1':request.form.get('member_instrument_1'),
                  'jam_notes':request.form.get('jam_notes'),
              })
              return redirect(url_for('get_jams'))
      return render_template('editjam.html',
          jam=the_jam,
          instruments=mongo.db.instruments.find(),
          counties=mongo.db.counties.find(),
          username=session['username'])
  </code></pre>
  
  <p>I then want to be able to say, in the html</p>
  
  <pre><code>{% if jam_owner == username %}
  xyz
  {% endif %}
  </code></pre>