I am new to using MongoDB and I am currently struggling with the db.find() command. I am trying to query my user database and retrieve a list of all users using Python…
I can get the list of my users by using the following command.
users = db.user.find()
where I am and if I list the variable users I get the following:
for obj in users:
print(obj)
Yields the following:
bossmandave@Davids-MacBook-Pro-2 kld9-bazaar % cd "/Users/bossmandave/Library/Mobile Documents/com~apple~CloudDocs/KLD9 Bazaar/kld9-bazaar"
bossmandave@Davids-MacBook-Pro-2 kld9-bazaar % /usr/local/bin/python3.9 "/Users/bossmandave/Library/Mobile Documents/com~apple~CloudDocs/KLD9 Bazaar/k
ld9-bazaar/main.py"
{'_id': ObjectId('61358b63af884f0bacbd8775'), 'email': 'johnDoe2@abc123.com', 'phone': '123456789', 'preferences': ['pref 1', 'pref 2'], 'status': 'private', 'uid': 'E943F20A-82B6-4FF2-8460-F8D369E6C51B', 'cart_id': None, 'date_created': datetime.datetime(1, 1, 1, 0, 0), 'date_updated': datetime.datetime(1, 1, 1, 0, 0), 'first_name': 'John', 'hashed_password': None, 'is_Oowner': True, 'is_admin': False, 'last_name': 'Doe2', 'user_created': None, 'user_updated': None, 'address': {'street': '123 2nd St.', 'street1': '', 'city': 'Jacksonville', 'state': 'Florida', 'postal': '49504', 'country': 'United States'}, 'to_delete': False, 'card': {'name_on_card': 'John Doe2', 'card_number': Decimal128('1111222233334444'), 'card_type': 'credit', 'card_issuer': 'Mastercard', 'expiry_date': datetime.datetime(2027, 12, 31, 16, 0), 'cvc_code': 123, 'is_primary': True}}
{'_id': ObjectId('61358b72af884f0bacbd8776'), 'uid': 'B38AC513-06F6-47A5-9AFC-2B38645D492D', 'phone': '123456789', 'email': 'johnDoe3@abc123abc.com', 'preferences': ['pref 1', 'pref 2'], 'cartID': None, 'status': 'private', 'card': {'name_on_card': 'John Doe3', 'card_number': Decimal128('1111222233334444'), 'card_type': 'cedit', 'card_issuer': 'Visa', 'expiry_date': datetime.datetime(2025, 5, 14, 16, 0), 'cvc_code': 456, 'is_primary': True}, 'date_created': datetime.datetime(1, 1, 1, 0, 0), 'date_updated': datetime.datetime(2021, 9, 12, 8, 0, 17, 351000), 'first_name': 'John', 'hashed_password': None, 'is_admin': False, 'is_owner': False, 'last_name': 'Doe3', 'to_delete': False, 'user_created': None, 'user_updated': None, 'address': {'street': '123 3rd St.', 'street2': '', 'city': 'Bankok', 'state': '', 'country': 'Thailand', 'postal': 259859}}
bossmandave@Davids-MacBook-Pro-2 kld9-bazaar %
But I cannot get the program to print each record out ?? I can’t seem to get into each object and print out data according to the object.
I am quite sure this is a simple fix, but I cannot seem to get it. What am I doing wrong. My initial thinking is that I may need to use a dictionary? Am I on the right track?

