Saturday 10 July 2021

Mongod.service not found => Pop from an empty deque => Authentication failed



The Problem

I'm getting started with MongoDB on Python, I have a Ubuntu machine in my local network and MongoDB is installed there. When I try to connect with database using Python from Mac it throughs me an error. I searched about it and found out there is a .service called mongod.service that needs to be started along with mongodb.service. But when I try to start the mongod.service the it says the .service doesn't even exist. I tried both with IP and mongodb url, nothing works.

Ubuntu Terminal

$ sudo service mongod start
$ Failed to start mongod.service: Unit mongod.service not found.
$ sudo systemctl start mongod
$ Failed to start mongod.service: Unit mongod.service not found.



DataBase Link (a)

mongodb://user:password@192.168.0.106/database

Python Script (a)

#!/usr/bin/env python3

from pymongo import MongoClient

client = MongoClient('mongodb://user:password@192.168.0.106/database')

db = client['database']

collection = db['collection']

json = dict(message='hello world', token=0)

collection.insert_one(json)

macOS Terminal (a)

pymongo.errors.ServerSelectionTimeoutError: 192.168.0.106:27017: [Errno 61] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 60e140982a43032aef0dd634, topology_type: Single, servers: [<ServerDescription ('192.168.0.106', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('192.168.0.106:27017: [Errno 61] Connection refused')>]>



DataBase Link (b)

mongodb+srv://user:password@cluster0.h9fmz.mongodb.net/database?retryWrites=true&w=majority

Python Script (b)

#!/usr/bin/env python3

from pymongo import MongoClient

client = MongoClient('mongodb+srv://user:password@cluster0.h9fmz.mongodb.net/database?retryWrites=true&w=majority')

db = client['database']

collection = db['collection']

json = dict(message='hello world', token=0)

collection.insert_one(json)

macOS Terminal (b)

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pymongo/pool.py", line 1278, in _get_socket
    sock_info = self.sockets.popleft()
IndexError: pop from an empty deque

During handling of the above exception, another exception occurred:
.....
.....
.....
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}



Note That

  • I'm providing the correct username and password for the database.
  • I'm using a machine on my local network, which is not a live server.
  • I've also tried the following commands but they did not solve anything.

Ubuntu Terminal

$ mongod --auth --port 27017
$ mongod --port 27017
$ sudo rm /var/lib/mongodb/mongod.lock
$ sudo mongod --repair





from Mongod.service not found => Pop from an empty deque => Authentication failed

No comments:

Post a Comment