0

I use the following query to fish for all men in a database:

f = pd.DataFrame(x for x in collection.find({"gender": "M"},{"_id":0}))

How could I find only the men where the "name" starts with an "A". Obviously I could filter the resulting huge DataFrame but how can I avoid creating this Frame in the first place.

Many thanks

1 Answer 1

2

You can use a MongoDB regular expression query, something like:

from bson.regex import Regex

f = pd.DataFrame(x for x in collection.find({"gender": "M", "name": Regex(r"^A.*")},{"_id":0}))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.