0

I want to use a wildcard in a query to select all records from a collection.

I have tried to use * and % as a wildcard for matching zero or all characters. But it doesn't work.

from pymongo import MongoClient
import datetime

client = MongoClient("mongodb://localhost:27017/")
database = client["local"]
collection = database["someDB"]

if flag = True:
    ch = "Pass"
else:
    ch = "*"

query = {}
query["Current Stage"] = ch

cursor = collection.find(query)
try:
    for doc in cursor:
        print(doc)
finally:
    client.close()

It was expected that all entries from the collection come up when the Flag is False. I have tried "*" and "%" as matching character.

Dmitrii Sidenko
  • 660
  • 6
  • 19
pankaj
  • 470
  • 5
  • 11
  • That was all I needed. Regex answers to my problem. Thanks for pointing out the Regex option. – pankaj Jun 06 '19 at 07:01

1 Answers1

1

You could perhaps try a regular expression? With RegEx you can use a dot (.) as a wildcard when you know the number of characters and backslash dot ( /.) when you don't know the number of characters, which you could use in your code. https://regexone.com/lesson/wildcards_dot (Sorry, don't have enough rep for a comment)

Janie
  • 56
  • 1
  • 9