MongoDB and Pymongo, query FULLTEXT in all collections

I have a local MongoDB database with multiple collections. I use pymongo in jupyter notebook, what I would like to do is run a query FULLTEXT looking for the data on all the collections present. is it possible to do this? if so how could i proceed?

from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017/')
client.list_database_names()
out: ['admin', 'config', 'local']

In local I have a more collection: this is what I do with just one collection

db = client["local"]
firstdb = db["firstdb"]

result = db.firstdb.find({"email": {"$regex":"test","$options": 'i'}})
for item in result:
    print(item['email'],item['log'])

in essence I would like to perform an email query also on secondb, thirdb, fourthdb, etc. etc.



Read more here: https://stackoverflow.com/questions/66232570/mongodb-and-pymongo-query-fulltext-in-all-collections

Content Attribution

This content was originally published by scofx at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: