I have a bunch of documents that consists of fields "Data" and "Text". Some docs have either one, while some have neither of these. How would I query through pyMongo to get documents that HAVE the field "Data" and DO NOT HAVE the field "Text"?
I've tried the below queries but mongo doesn't return any files.
METHOD 1:
files = collection.find({"Data": {"$exists": "true"}, {"Text": {"$exists": "false"}})
for file in files:
print(file)
METHOD 2:
files = collection.find({"$and": [{"Data": {"$exists": "true"}}, {"Text": {"$exists": "false"}}]})
for file in files:
print(file)
NOTE: I'm currently trying the query on a database where no collections have the "Text" field (yet), but the query should still work w.r.t the logic. It being:
Return docs with "Data" AND not having "Text"