Get data from server

I want to pull data from the server instantly with python. I couldn’t find any api

You mean like data from the DB?

1 Like

I created sync on a server.
I want to get the data (data in the picture) instantly with python

You can connect directly from python to your server mongo db instance. Search on forum how to backup db and you’ll find an example in python.

What should I write in parse and user part?

import pprint
import pymongo

MONGO_HOST = "asfasdf.moralis.io"
MONGO_PORT = 43234

con = pymongo.MongoClient(MONGO_HOST, MONGO_PORT)
user_table = con['parse']['_User']
pprint.pprint(user_table.find_one())

instead of _User you should write the table name that you want

1 Like

i use this code and added my ip address:
"MONGO_HOST = “ideletethis.usemoralis.com
MONGO_PORT = 2053

con = pymongo.MongoClient(MONGO_HOST, MONGO_PORT)
user_table = con[‘parse’][‘lokonooooooo’]
pprint.pprint(user_table.find_one())"

error:


 File "c:\Users\Administrator\Desktop\New folder (2)\mai.py", line 18, in <module>
    pprint.pprint(user_table.find_one())
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\collection.py", line 1114, in find_one
    for result in cursor.limit(-1):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\cursor.py", line 1159, in next
    if len(self.__data) or self._refresh():
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\cursor.py", line 1057, in _refresh
    self.__session = self.__collection.database.client._ensure_session()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\mongo_client.py", line 1603, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\mongo_client.py", line 1553, in __start_session
    server_session = self._get_server_session()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\mongo_client.py", line 1589, in _get_server_session
    return self._topology.get_server_session()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\topology.py", line 530, in get_server_session
    session_timeout = self._check_session_support()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\topology.py", line 514, in _check_session_support
    self._select_servers_loop(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pymongo\topology.py", line 216, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: Got response id 808465440 but expected 32662, Timeout: 30s, Topology Description: <TopologyDescription id: 61e062e6589ffdaca50c7a29, topology_type: Unknown, servers: [<ServerDescription ('yrkjfjm789if.usemoralis.com', 2053) server_type: Unknown, rtt: None, error=ProtocolError('Got response id 808465440 but expected 32662')>]>

After you whitelist your IP, you can find in your server settings the IP and port that you should use here

now it worked but how do i pull the newest transfer. so the newest

You can check the documentation for how to use mongo in python, or you can read all the rows with .find

can you write the code. i tried this but it didn’t work

pprint.pprint(user_table.collection.find().limit(1).sort([(’$natural’,-1)]))

output: <pymongo.cursor.Cursor object at 0x000002A27CCD0A90>

Just try to iterate that cursor object to get the data, or convert it to a list