Hi, im trying to dev my local mongodb. For that im using docker inside ubuntu and python. I first started to initiate one simple database using docker-compose.
And made a verry simple interface in python.
It works perfectly, so i tried to make a replicaset for some reason im not able to use docker-compose for replicaset, i saw some documentation online and also used that documention and always happened the same! The containers are created but unable to run it but dont shows any error. So i ran it step by step and understood that if i run the mongo containers with enviroments would happen the same so i run the simple following commands:
sudo docker run -p27017:27017 -d --name m1 --net mongonet mongo --replSet myset
sudo docker run -p27027:27017 -d --name m2 --net mongonet mongo --replSet myset
sudo docker run -p27037:27017 -d --name m3 --net mongonet mongo --replSet myset
sudo docker exec -it m1 mongo
config = { "_id" : "myset", "members" : [ { "_id" : 0, "host" : "m1:27017" }, { "_id" : 1, "host" : "m2:27017" }, { "_id" : 2, "host" : "m3:27017" }] }
rs.initiate(config)
Tested if it was working and all good for now.
So i tryed again the connection with the python app and it showed this:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\Asus\PycharmProjects\pythonProject1\interface.py", line 14, in transfer
db_collection.insert_one(data)
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\collection.py", line 524, in insert_one
self._insert_one(
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\collection.py", line 474, in _insert_one
self.__database.client._retryable_write(
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\mongo_client.py", line 1339, in _retryable_write
with self._tmp_session(session) as s:
File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\mongo_client.py", line 1616, in _tmp_session
s = self._ensure_session(session)
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\mongo_client.py", line 1603, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\mongo_client.py", line 1553, in __start_session
server_session = self._get_server_session()
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\mongo_client.py", line 1589, in _get_server_session
return self._topology.get_server_session()
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\topology.py", line 530, in get_server_session
session_timeout = self._check_session_support()
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\topology.py", line 514, in _check_session_support
self._select_servers_loop(
File "C:\Users\Asus\PycharmProjects\pythonProject1\venv\lib\site-packages\pymongo\topology.py", line 216, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: m2:27017: [Errno 11001] getaddrinfo failed,m1:27017: [Errno 11001] getaddrinfo failed,m3:27017: [Errno 11001] getaddrinfo failed, Timeout: 30s, Topology Description: <TopologyDescription id: 622c1970456f0a8a08b35096, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('m1', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('m1:27017: [Errno 11001] getaddrinfo failed')>, <ServerDescription ('m2', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('m2:27017: [Errno 11001] getaddrinfo failed')>, <ServerDescription ('m3', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('m3:27017: [Errno 11001] getaddrinfo failed')>]>
Searched a solution but nothing.
I dont know what more i can do and im stuck.Can you guys help me?
Here is the code used in the python app:
#bibliotecas
import tkinter as tk
import pymongo
#variaveis referentes ao mongo
url="mongodb://admin:password@localhost:27017"
client = pymongo.MongoClient(url)
data_base = client.utad
coll=data_base.utad
db_collection = data_base.alunos_utad
db_col2=data_base.novo_doc
#função para tranferir os dados para a db quando o button save é premido
def transfer():
data={"name":input0.get(),"sobrenome":input.get(),"email":input2.get(),"Al":input1.get(),"curso":input3.get(),}
db_collection.insert_one(data)
def search():
y=input0.get()
t=input.get()
q=input1.get()
w=input2.get()
r=input3.get()
if t==""and q=="" and w=="" and r==""and y!="":
data = {"name": input0.get()}
x=db_collection.find_one(data)
print(x)
label4["text"]=x
if y==""and q=="" and w=="" and r=="" and t!="":
data = {"sobrenome": input.get()}
x=db_collection.find_one(data)
print(x)
label4["text"]=x
if t==""and y=="" and w=="" and r==""and q!="":
data = {"Al":input1.get()}
x=db_collection.find_one(data)
print(x)
label4["text"] = x
if t==""and q=="" and y=="" and r=="" and w!="":
data = {"email": input2.get()}
x=db_collection.find_one(data)
print(x)
label4["text"] = x
if t==""and q=="" and w=="" and y=="" and r!="":
data = {"curso": input3.get()}
x=db_collection.find_one(data)
print(x)
label4["text"] = x
if y==""and t=="" and q=="" and r=="" and w=="":
print("Nenhum valor inserido imprimir tudo na collection")
for x in db_collection.find():
print(x)
label4["text"] = x
else:
data = {"name": input0.get(), "sobrenome": input.get(), "email": input2.get(), "Al": input1.get(),
"curso": input3.get()}
x=db_collection.find_one(data)
print(x)
label4["text"] = x
#criar uma janela grafica
root= tk.Tk()
#definir o tamanho da janela
canvas= tk.Canvas(root,height=500,width=400)
canvas.pack()
#definir a framework
frame=tk.Frame(root)
frame.place(relwidth=1,relheight=1)
#colocar um button
button= tk.Button(root, text="Save",command=transfer)
button.pack()
#labels e caixas de texto relacionadas a entroduzir dados
label=tk.Label(frame, text="Interface para introduzir dados")
label.pack()
lab=tk.Label(frame, text="Nome")
lab.pack()
input0=tk.Entry(frame, bg="red")
input0.pack()
lab=tk.Label(frame, text="Sobrenome")
lab.pack()
input=tk.Entry(frame, bg="red")
input.pack()
lab1=tk.Label(frame, text="Al")
lab1.pack()
input1=tk.Entry(frame, bg="red")
input1.pack()
lab2=tk.Label(frame, text="email")
lab2.pack()
input2=tk.Entry(frame, bg="red")
input2.pack()
lab3=tk.Label(frame, text="curso")
lab3.pack()
input3=tk.Entry(frame, bg="red")
input3.pack()
#procurar um elemento qualquer
label4=tk.Label(frame,bg="blue")
label4.pack()
button1= tk.Button(root, text="Find",command=search)
button1.pack()
#iniciar a aplicação
root.mainloop()