The Code:
import pymongo
import time
import datetime
myclient = pymongo.MongoClient("mongodb+srv://pss:nm22@cluster0.uxfb5.mongodb.net/<dbname>?retryWrites=true&w=majority")
mydb = myclient["hcd"]
mycol = mydb["c61"]
x=datetime.datetime.now()
print(x)
ts1 = time.time()
print(ts1)
mydoc=list(mycol.find({ "pId":"6993341507" }, {"compid" : 0, "comp" :1, "compst":1}))
# ))
# {"id1": 1, "drId": 0, "name": 1, "cno":1, "email":1, "address":1,"compid":0,"comp":0,"compst":0,"personalh":0, "presenth":0, "pasth":0,"fh":1
ts2 = time.time()
print(ts2)
td= ts2-ts1
print('The difference is approx. %s seconds' % td)
print(mydoc)
The Output:
2021-03-16 16:07:33.998910
1615891053.9989104
Traceback (most recent call last):
File "E:\nm21\readmongoc61.py", line 12, in <module>
mydoc=list(mycol.find({ "pId":"6993341507" }, {"compid" : 0, "comp" :1, "compst":1}))
File "C:\Python\Python39\lib\site-packages\pymongo\cursor.py", line 1207, in next
if len(self.__data) or self._refresh():
File "C:\Python\Python39\lib\site-packages\pymongo\cursor.py", line 1124, in _refresh
self.__send_message(q)
File "C:\Python\Python39\lib\site-packages\pymongo\cursor.py", line 999, in __send_message
response = client._run_operation_with_response(
File "C:\Python\Python39\lib\site-packages\pymongo\mongo_client.py", line 1368, in _run_operation_with_response
return self._retryable_read(
File "C:\Python\Python39\lib\site-packages\pymongo\mongo_client.py", line 1471, in _retryable_read
return func(session, server, sock_info, slave_ok)
File "C:\Python\Python39\lib\site-packages\pymongo\mongo_client.py", line 1360, in _cmd
return server.run_operation_with_response(
File "C:\Python\Python39\lib\site-packages\pymongo\server.py", line 136, in run_operation_with_response
_check_command_response(
File "C:\Python\Python39\lib\site-packages\pymongo\helpers.py", line 167, in _check_command_response
raise OperationFailure(msg % errmsg, code, response,
pymongo.errors.OperationFailure: Cannot do inclusion on field comp in exclusion projection, full error: {'operationTime': Timestamp(1615891048, 1), 'ok': 0.0, 'errmsg': 'Cannot do inclusion on field comp in exclusion projection', 'code': 31253, 'codeName': 'Location31253', '$clusterTime': {'clusterTime': Timestamp(1615891048, 1), 'signature': {'hash': b'\xfeu\xdb\xa7c\xfa=\xf20\xed`\xb6s\xd3xsm\xcaV|', 'keyId': 6920164380919201795}}}