0

I want to print the _id part of the results by running a query on the mongo db, but I am getting the "list index out of range" error.

view;

def deleted(request):
    q1=('XX')
    q2=('XX')
    client = MongoClient("XX")
    database = client["XX"]
    collection = database["XX"]
    query = {}
    query["Marketplace"] = q1
    query["$or"] = [
      {
        "Tuyx": q2
      }
    ]
    cursor = collection.find(query)
    print(cursor)
    sonuc= loads(dumps(cursor))
    id=sonuc[0]["_id"]   
    print(id)                  
    client.close()
    return render(request, 'deletedlisting.html', {'id':id} )

ti want to print _id value as string;

enter image description here

hma
  • 75
  • 5
  • A cursor is not a list. Have a look at https://stackoverflow.com/questions/6680659/pymongo-cursor-iteration – Joe Dec 02 '21 at 20:54

0 Answers0