skip to Main Content

Connect to MongoDB via python

I'm trying to connect to mongodb using python and code: myclient = pymongo.MongoClient("mongodb://root:password@mongo:27017/database_sample?authSource=admin") db = myclient.database_sample my_collection = db["database"] but I'm getting pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}

VIEW QUESTION

Mongodb – Why does my code not write the data it receives from the build_info function to the json file?

api = shodan.Shodan(api_key) query = 'MongoDB Server Information n{ "process": "mongod" port:27017' build_info_arr = [] try: results = api.search(query) print('Total Results: %sn' % results['total']) for result in results['matches']: if "Authentication partially enabled" not in result['data']: print('IP: {}'.format(result['ip_str'])) ip: str =…

VIEW QUESTION

checking if a value exists in mongodb collection using pymongo

I have a a mongo db table in the following format [{"url":"www.example1.com", "name":"hans","age":30}, {"url":"www.example2.com", "name":"x","age":34}, {"url":"www.example3.com", "name":"y","age":35}, {"url":"www.example4.com", "name":"z","age":36}, {"url":"www.example5.com", "name":"b","age":37}] I have two tables where i need to check for under two if conditions. I did in the following…

VIEW QUESTION

How to find_one in mongodb if the key is not always present?

I have a following mongodb: some records looks like {'_id': ObjectId('62790ce20375a639af1d8676'), 'visit_id': 594817704, 'transaction' : 10} some has only this form: {'_id': ObjectId('62790ce20375a639af1d8679'), 'visit_id': 594817704} Using this code I can search for all collections that consists of transaction_id: collection.find({'transaction_id': {…

VIEW QUESTION
Back To Top
Search