0

I have a quick question: I have a MongoDB Database with a collection of dummy data. I used the follwoing code to display all documents within my collection (in this case FlightNo and Terminal):

def getAllFlights():
        for x in flightsCol.find({}, {"_id": 0, "number": 1, "terminal": 1}):
        print(x)

This works pretty good and the Output looks like that:

{'number': 'XXA54', 'terminal': 'O2'}
{'number': 'LH587', 'terminal': 'PO'}
{'number': 'KLH552', 'terminal': 'LO556'}
{'number': 'LO552', 'terminal': 'H1'}
{'number': 'HHG565', 'terminal': 'H1'}
{'number': 'TRE223', 'terminal': 'LK1'}
{'number': 'JUZ556', 'terminal': 'KL234'}

My question now: How can I display the output as plain text like:

XXA54 O2

Thank you for your help!

Michele

1 Answer 1

1

print each part of the returned dictionary:

def getAllFlights():
    for x in flightsCol.find({}, {"_id": 0, "number": 1, "terminal": 1}):
        print(x["number"],x["terminal"])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.