How to work with output from mongodb

Hi! I am quite new with collections.
I got list of values for item from MongoDB.
The list for a single item looks like next:
[ {‘_id’: ‘123’, ‘filename’: ‘4819000400002/200013006/9’, ‘length’: 11511, ‘chunkSize’: 261120, ‘uploadDate’: datetime.datetime(2024, 2, 21, 16, 45, 35, 654000), ‘metadata’: {‘encoding’: ‘UTF-8’, ‘contentType’: ‘application/xml’, ‘createdBy’: ‘UserName’}}]
How do I find something in it?
I tried to find if list contains _id
List Should Contain Value ${RESULTS} 123
But nothing was found, but it should. What am I doing wrong?

123 is the value of the dictionary key _id. If your list is ${RESULT}, then the dictionary is the first element of the list, and you should use some keyword like Dictionary Should Contain Value (I don’t know if exists).

Dictionary Should Contain Value    ${RESULT[0]}    123
1 Like

Sorry, but ${RESULTS} is a list, not dictionary. I’ve checked it already. Seems like [ {‘_id’: ‘123’, ‘filename’: ‘4819000400002/200013006/9’, ‘length’: 11511, ‘chunkSize’: 261120, ‘uploadDate’: datetime.datetime(2024, 2, 21, 16, 45, 35, 654000), ‘metadata’: {‘encoding’: ‘UTF-8’, ‘contentType’: ‘application/xml’, ‘createdBy’: ‘UserName’}}] is a solid value (whole string is a one value).
But I tried your solution and got “nothing was found”
Maybe I need to convert it to string?

Yes ${RESULTS} is a list but the first of its elements (the unique), is a dictionary.

List elements in Python (and RF) are addressed by [ ] with numerical values, Dictionaries values can be obtained by their keys and uses { } to set the keys and values, if it was in Python, you would write:

if result[0]['_id'] == '123':
    print("Dictionary value for _id is 123")
1 Like