Problem connecting to mongodb created by pymongo and/or mongoose?

Hello,

I am having a problem connecting to some database on MongoDB Atlas if the database is created by pymongo (python). The same problem happens with the database created by mongoose. Is this the case that parse can only access to the mongodb database created by parse?

In our project, we first need to use a python code on the server, then we are creating mongodb database (on Atlas) with pymongo. However, when I try to read the data from my swift app through parse server, it seems that I cannot access the mongodb database created by pymongo, so I am wondering if this is a known thing. I don’t have this problem at all for the database on Atlas created by parse.

Thanks!
Sumire

The database can only be accessed by Parse Server if it is in the expected format. For example, all collections have to be listed at the schema, dates, and files have specific formats. So you can actually use python to insert data to a Parse Server database if you take care to insert in the expected format. It is not recommended though.

Oh I see! So I tried to do what’s described in the below link in order to write in mongodb (in parse format) from python, after specifying our parse server (I am deploying this parse server on heroku with its appID, rest api key, databaseUri, etc, as I am doing for my other app).

import http.client
import json 

connection = http.client.HTTPSConnection('https://myInstanceName.herokuapp.com', 443)

connection.connect()
connection.request('POST', '/parse/classes/GameScore', json.dumps({
       "score": 1337,
       "playerName": "Sean Plott",
       "cheatMode": False
     }), {
       "X-Parse-Application-Id": "${MyAppID}",
       "X-Parse-REST-API-Key": "${MyRestAPIKey}",
       "Content-Type": "application/json"
     })
#results = json.loads(connection.getresponse().read())
results = connection.getresponse().read()

print(results)

But it seems like it is not finding the heroku page as print statement shows something like:


b’\n\t\n\t \n\t\t\n\t\t\n\t\tNo such app\n\t\t\n\t\t html,body,iframe {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t } … src="//www.herokucdn.com/error-pages/no-such-app.html">\n\t \n\t’


(I had to replace “import json, httplib” by “import http.client, json” and also use “http.client.HTTPSConnection(…” instead of "
httplib.HTTPSConnection(…" )

I also tested this python code with my other parse server instance on heroku (that is functioning well with my swift app), but got the same problem, so it seems like there is something wrong with my python code above??

Do you guys have any suggestions about what can be wrong/how to fix this?

Thanks a lot for your help!!
Sumire

ok, so if we remove “https://” part from below line, it advances a bit more.

connection = http.client.HTTPSConnection('myInstanceName.herokuapp.com', 443)

connection.connect()
connection.request('POST', '/parse/classes/GameScore', json.dumps({
       "score": 1337,
       "playerName": "Sean Plott",
       "cheatMode": False
     }), {
       "X-Parse-Application-Id": "${MyAppID}",
       "X-Parse-REST-API-Key": "${MyRestAPIKey}",
       "Content-Type": "application/json"
     })
results = json.loads(connection.getresponse().read())

print(results)

Now the print statement above gives,

{‘error’: ‘unauthorized’}

But it still cannot create object on the database…
Any ideas? Thanks!

Could you double check your application id and rest key? Could you also check if there is public write permissions for the GameScore class? You can also try to add the master key with the X-Parse-Master-Key header in order to figure out if it is a permission problem.

Thanks for your reply! Yes, I double-checked all these keys. Actually, now it sort of works if I add the client key or the master key. It doesn’t matter if I keep or remove the rest api key. Also, I had to change the format of “${VariousKeys}” by just “VariousKeys”.

Is it ok to use the client key instead of the rest api key in general (I am also just using the client key on my swift app)?

Also, since it doesn’t work with just the rest api key(without the client or master key) , so that seems like the rest api key was not set correclty? I set it on index.js file as (same way as some other keys)

restApiKey: process.env.REST_API_KEY || ‘XXXXXX’

Also, in case, I added the same key string from heroku’s config variable page using “REST_API_KEY” as the parameter name (as we can set other parameters). Does that sound reasonable?

Thanks!

In your Parse Server configuration, the Rest API Key should be passed in the field called restAPIKey as you can see here. That’s probably the problem. Try to fix the configuration and let me know.

Thank you very much!!! That was exactly the issue. Happy Holidays!