Forums

Does Pythonanywhere have mongodb?

Any plans to have it installed? Thanks

AFAIK we only have SQLite and MySQL. Soon we will also have PostgreSQL.

From the FAQ:

What kinds of databases can I use?

PythonAnywhere supports MySQL and SQLite. We're considering adding MongoDB
and PostgreSQL in the future -- if you're interested in either (or something
else entirely), let us know!

To start using MySQL, you'll need to go to the MySQL tab on your dashboard,
and set up a password. You'll also find the connection settings (host name,
username) on that tab, as well as the ability to create new databases.

MongoDB is a very popular request. Right behind Postgres. It does present some challenges in a multi user environment. It might be that we have to write our own user access layer from scratch.

CouchDB is another alternative. I'm less interested in Postgresql, although I might be if coding stored procedures is included. In any case, either would open the door to users that get shut out by other services (many of whom say they will support something and then do not support that in an effective way).

@dscapuano: Now is the time to make sure PA staff know what you want. Your statement about other services not supporting in an effective way has me writing this. Now is the time while PA is working out the implementation details. Tell them what is important to you. What you expect the feature to accomplish. They can't be sure to make it work as expected if they don't know what you are expecting. So, please provide details and I'm quite sure they will incorporate them if feasible.

Anything not feasible will hopefully bring with it a suggested work around that will keep you in business.

Most of these NoSQL solutions seem to share two things in common - they're quite different from SQL setups and they're quite different from each other. I'm guessing this means that there may be a larger incremental cost to supporting each one than there might be to setting up a random RDBMS, which are much more of a known quantity.

Also NoSQL DB's seem to be tailored to application-specific needs much more closely. This isn't to say that there can't be a good generic setup, but I think it's worth being cautious.

So, it's probably worth spending a decent amount of time picking the right initial candidate. I guess MongoDB may be a reasonable choice, based on my very limited experience, since it seems to be suited to the sorts of tasks one might have used a standard RDBMS for. Some of the others seem more tailored for massive data warehousing and log analysis, and I suspect that PA isn't really the right service for people who have those sorts of large-scale computing requirements - at least not right now. In the future, who knows! (^_^)

In short, I think the current seeming approach of getting some solid traditional SQL options on the table is absolutely the right thing to do, but as a2j says it's also the time to canvas for opinion so that when the time does come, the best option is already clear.

I could probably have saved everyone a lot of reading by writing "a2j: me 2" but I never did like AOL.

Can we use PyMongo and just connect to an outside service like MongoLab? I'm trying but so far not working....

That should work for paying customers like you (thanks :-)

Could you share the stack trace or other error you get?

I'm back to basics here. I have a simple app working in Flask now and am going to see if I can get PyMongo working to connect to MongoLab. That would do the trick. Happy to pay for a service that works and is well supported. Just getting started here though!

Great! Let us know how you get on, we're here to help.

Just to confirm that the connection to MongoLab works as expected:

from pymongo import MongoClient
connection = MongoClient(MONGO_URL, MONGO_PORT)
db = connection[MONGO_DB]
db.authenticate(MONGO_USER, MONGO_PWD)

Excellent, thanks for confirming!

+1 on MongoDB support, although Mongolab looks good too!

Bumped it up on our list.

Just signed up to the free account to trial this service. Not even got my first web app running yet, but already blown away by this!

My whole stack is here already (flask, wtforms, pymongo) without me having to do anything. If you could offer mongo instances too, that would be incredible. Will be signing up for a developer hosting account very soon.

Big thank you to the poster that mentioned mongo lab - looks like a great service too.

Cheers for the great work!

Thanks, brightattic -- glad you like it! Please do let us know here in the forums -- or privately by the "Send feedback" link at the top of the page -- if you have any comments.

Hi,

To clarify, is access to MongoLab only for paid accounts? It's URL is on the whitelist for free accounts, but I'm getting

ConnectionFailure: could not connect to xxxxxxxxxxxxx: [Errno 111] Connection refused

when trying to connect from my app.

Cheers.

If the MongoLab connection is via http on port 80, then it should work for free accounts. Otherwise, it will only work for paid accounts.

So I see the Mongolab connection code above. Do I also have to put an import pymongo in my wsgi file like I did for bottle?

Will that do the trick?

@glenn: Shouldn't that be port 80 or port 443?

Well, there's a few bugs in some of the popular python HTTPS client libraries (see posts re tweepy, ad nauseam), which means that they don't always work well through the proxy...

Got it...thx...☺

When setting up a mongolab remote connection, what do I put as the URI to connect to python anywhere? I tried "mongodb://pythonanywhere.com" and that doesn't seem to be working. I've also tried my username prepended to the pythonanywhere and I keep on getting "server is unreachable" on mongolab. emilmont would you mind helping?

When setting up a mongolab remote connection, what do I put as the URI to connect to python anywhere? I tried "mongodb://pythonanywhere.com" and that doesn't seem to be working. I've also tried my username prepended to the pythonanywhere and I keep on getting "server is unreachable" on mongolab. emilmont would you mind helping?

I'm a bit confused -- are you trying to connect from MongoLab to PythonAnywhere? We don't host MongoDB here, so that won't work. If you're trying to connect from PythonAnywhere to MongoLab then your connection settings will look something like mongodb://my-db-user:my-db-password@ds033217.mongolab.com:33217/my-database -- see this page on MongoLab's support pages.

However, even then, you'll need a paid PythonAnywhere account for it to work. Free PythonAnywhere accounts only allow HTTP access out to a specific set of other websites. Paid ones have unlimited Internet access.

Just to hiccup an old chestnut, where do you stand with adopting a nosql db such as MongoDB?

We had a brief look at adding Mongo a few weeks ago. The result of our investigation is that our architecture doesn't support it at the moment. The architectural changes that are necessary are things that we want to do for many other reasons. They're quite big changes and so they could take a while to get done, but when they're done, providing Mongo and other NoSQL databases should be fairly simple.

Sounds good! I have an account with Mongolabs, and going out to them should be ok for now. However, the sooner the better with Mongo on PA, because your service is the best in this business.
Thanks, Dave Capuano

Thanks Dave :-) There's an upvote on the to-do list on your behalf.

+1 for MongoDB. I'm using the MongoLab solution for now. Thanks for letting us know about it!

Thanks for letting us know! I've added your +1 to our to-do list.

For those who want to have a NoSQL solution now you could look at this Release Announcement for PostgreSQL 9.2. Toward the bottom it references methods to use PG as a NoSQL solution...☺

But... is it Web Scale?

Does anyone have a sample dataset/simple app we can try it out with? If not we could generate one if there is interest in order to verify prior to anyone developing a real world solution that may suffer from lackluster horsepower. ͡° ͜ʖ ͡°

+1 for me regarding MongoDB! I'll get an even warmer/fuzzier feeling about PA if MongoDB is added.

Thanks! I've added the upvote to our DB. It's getting pretty high up the list, though PostgreSQL is still ahead...

Hi all,

To those of you who have some experience with MongoDB: I have successfully connected my app to a MongoDB database on MongoLab and saving some data from an input form works like a charm. But somehow I totally do not understand how to load the data from the database. I do understand how to run queries like

collection.find_one()

etc but I just don'z understand to actually access the data inside the documents.

Assuming I have a document

quser = {"date": datetime.datetime.utcnow(),
    "age": age,
    "gender": gender_choice,
    "nation": nation,
    "industry": industry
]

How on earth can I assign the string variable in the field "nation" for example to a Python variable "a" ??

Thanks for help

OK, I totally missed the fact that the document is actually just a Python dictionary. So it works now by just saying:

a = quser['nation']

or

field_list = []
for field_name, value in quser.items():
    field_list.append(value)

+1 for MongoDB! I would upgrade my account to WebDev/Startup when MongoDB is supported!

Loving pythonanywhere, great job!

Thanks! Upvote for Mongo noted :-)

+1 for Mongo for me, too. It's rapidly becoming my go-to data storage solution.

Thanks, greg -- noted.

Not sure if you guys already have me down as a +1 for MongoDB. If not, add me too :)

We didn't. We do now.

Haven't tried MongoDB yet but I've heard great praises about it. +1 for me. Also I'm interested in using it for Flask. Thanks.

Cool. I've added you to the list.

for me also MongoDb would be a real plus to PythonAnywhere.

I have a commercial project in mind that WILL run Mongodb. I would be glad to host it on Pythonanywhere. For yet, it still has to be developped (only at idea stage), so I still have some time before the need to host it.

+1 for Mongodb

OK, thanks! I've added the +1 to our tracker.

With a paying account you can access external Mongo databases, by the way, so if you're happy with using multiple providers for your infrastructure (us for hosting and, say, MongoHQ for the database) then you can start right away!

+1 from me for mongodb

Thanks for letting us know!

How much would you pay for a MongoDB service? $20 per month? plus some extra charges per GB of storage over some base amount, a bit like our custom plans?

+1 from me for MongoDB

Thanks! I've added another upvote to the ticket.

+1 for mongodb

+1 for mongodb

FWIW, I have had good luck with teaching using PythonAnywhere and the free database offering from MongoLabs.

https://mongolab.com/plans/pricing/

You need to be aware that when you connect to it you're already at a database, and you can't get a list of databases. So the usual 'show dbs' thing doesn't work and just tells you you're not authorized. I found this initially kind of a distraction, since I assumed the issue was because my password was wrong, but they just want you to go ahead and connect to your (only) database and past that it works fine. I suggested to them that they make that obvious somewhere, because it means you can't really move smoothly past the "show dbs" part of just about every mongo tutorial there is, and perhaps they have done so.

In any case, past that it works great. The only other caveat is that it requires access that isn't on the PA whitelist, so my students who wanted to use it were encouraged to get paid accounts, but the PA staff was helpful about temporarily whitelisting the addresses in question when necessary, and were my class to have had no other alternative for MongoDB I would have followed up on that further.

Bottom line, though, is that PA + MongoLabs looks like a pretty good option.

Hope this helps!

This is the code I use to access the MongoLab database:

import pymongo

client = pymongo.MongoClient("mongodb://<xxx>:<xxx.xxx.xxx>@ds<port>.mongolab.com:<port>/<databasename>")

db = client.<databasename>

print db.collection_names()

...where the bracketed values you will get when you sign up at MongoLabs. The code prints this:

[u'system.indexes', u'system.users', u'stuff', u'objectlabs-system', u'objectlabs-system.admin.collections']

And then you can go on from there...

I'd also would like to see MongoDB on PA, as I'm stuck and can't get my website working with the PA's free account. PA service is great, but unfortunately lack of local support for MongoDB is a dealbreaker for me as I require mongoDB and my website to run on the same system.

I'll shop around for something else, but I may come back if support for MongoDB is added at some point.

I like the PA service though.

@kenk have you looked at https://mongolab.com Good rates and a free account, I us it for the odd job where I need to use mongo

@graingerkid -- great suggestion. When we add MongoDB then we're probably going to do it by partnering with MongoLab or MongoHQ. For best performance, start your instance with them in the Amazon Web Services us-east-1 region, or the best approximation thereto.

Thanks for suggestion. I have seen MongoLab and I'll try to evaluate the option too. In my case MongoDB is very central to the project and, on paper, it would be beneficial to have it close to webserver. But in practice it may not be big factor. I'll try and report back on this topic.

I think MongoLabs' pricing is the same wherever you start the instance, so (unless I'm wrong on that) I'd definitely recommend us-east-1.

BTW I don't think MongoDB connections from inside PythonAnywhere will work from a free account, so you'd need a paying account to access MongoLabs from here. If you'd like us to temporarily enable outgoing connections to them from your account so that you can try before you buy, just let us know over the "Send feedback" link at the top right -- drop in a link to this forum thread so that the person dealing with it knows why you're asking for it.

Another +1 for MongoDB support :D

I recently upgraded to paid PA account. A quick test using MongoLabs worked a charm. But hey, if I'm paying here, let's get it all localised right here. Thumbs up for you guys.

Cool. I've bumped the ticket for you.

Just a thought, would it be within the realms of possibility to include a Mongo shell in the 'others' category on the Consoles tab? That could be used to connect directly to a MongoLab hosted instance.

You can do that yourself with a custom console. Just put the command that you'd use to connect to mongolab in the command field and it will start with that every time you click it.

@glenn, wouldn't we need the mongo program installed in order to do that? The command to connect to a MongoLab-hosted instance would be:

mongo ds12345.mongolab.com:12345/[database_name] -u [dbuser] -p [dbpassword]

Ah, looks like we don't have the mongodb client installed. Will fix that. In the meantime, you can use a python library like pymongo. Or you can also download the client manually:

cd
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.4.tgz
tar -xvf mongodb-linux-x86_64-3.0.4.tgz
ln -s ~/mongodb-linux-x86_64-3.0.4/bin/mongo ~/.local/bin/mongo
mongo

Great, thanks. I can confirm that downloading the client as above works and allows me to connect into my MongoLab-hosted instance.

I didn't create the link though, as for some reason I don't have a bin directory in my ~/.local/. So instead my custom console just uses the full path to the mongo binary.

that'll work too!

will add a ticket to include the mongo client as part of our standard image...

Hi Guys pythonanywhere newbie here, Ive been using pymongo package locally up until now, importing MongoClient and setting up a client with client=MongoClient() Im getting an connection refused error message.

pymongo.errors.ConnectionFailure: [Errno 111] Connection refused

Anyone Any Tips?

What mongodb server are you trying to connect to?

@glenn this is it, Ive been using localhost up until now...I'm looking into MongoLab here now after reviewing earlier comments. I assumed I could create a db locally here.

I don't know where you got that idea. We don't support mongodb servers at all at the moment. So you're getting connection refused because there is nothing to talk to there.

@glenn thanks for the info. Much appreciated :)

@glenn I am using the hacker account and I cannot connect to a mongo db at MongoLab. The problem is that the MongoLab is on MongoDB version 3.0.x and on pythonanywhere you use pymongo 2.7.1 which has authentication problems with MongoDB 3.0.x. I am running locally with pymongo 3.2.1 and it works perfectly, but when I upload the same code to pythonanywhere it fails because of an auth error. Is there any way to update the pymongo plugin to a newer version. Please let me know because this issue is critical for me.

Hi Martin, if you upgrade pymongo, does it help? Either by using a virtualenv or with the --user flag for pip?

https://help.pythonanywhere.com/pages/InstallingNewModules

@harry I updated with the --user flag and it works now. Thanks a lot

Thanks for confirming!

Can I check if the mongo was installed for use as a custom console? I'm using python code and pymongo but some admin would be some much easier in a console directly (I am using mlabs). Maybe I just need some step by step help, thanks in advance! (Post above "will add a ticket to include the mongo client as part of our standard image...", July 2015 I think refers) P.S. I love PA

I'm afraid we haven't got round to that no... Maybe you can download it and just run it from inside your home folder somehow though? If it needs compiling, we have gcc and so on...

I have also asked for the mongo client, pretty recently.

Since Harry proposed this first, I'll go ahead and mention it: it turns out that if you go find the mongo*tar.gz at their download site for Ubuntu 14 LTS and you unzip/unpack it, you get some binaries. One of them is mongo, but there are also things like mongodump and mongoimport/mongoexport, etc.

The download site is here:

 https://www.mongodb.com/download-center#community

You'll want to use wget to grab this:

https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-3.4.0.tgz

If you take these binaries and put them into ./local/bin, you're done. :-)

(As long as .local/bin is in your path, and perhaps you might have to restart bash...)

The mongo client connects to MLabs perfectly, and it functions as expected. Sometimes you have to read the docs very carefully to get the command line right, but in general it works quite well.

Best wishes,

-greg

Hi,

I have a free pythonanywhere account, does this mean I wont be able to access a remote MongoLab?

Thank you.

We have whitelisted mongolab in particular, and you will be able to access it over http/https. If you want to access anything else/over any other protocol you may need to upgrade.

FYI, and I'm sure you're aware of this, Mongolab has changed its url to "mlab.com" and the remainder of their URLs now derive from that.

-greg

Yup, *.mlab.com is on the whitelist too.

Just to clarify -- mongolabs will not work for free users, even though their site is on the whitelist. That's because the mongo protocol isn't over HTTP/HTTPS. More info here

Totally understood. But I do have students using it at the $5 level, and we've had great success with it. Thanks for the clarification.

Hello Admins,

Based on the thread, I wanting to confirm the cause behind what I am seeing. I am using pymongo/pymodm to interface with the mongolab instance (pymodm as the ORM).

I am getting the error:

pymongo.errors.ServerSelectionTimeoutError: ds139288.mlab.com:39288: [Errno 111] Connection refused

I am presuming, since I am free user, even though *.mlab.com is on the whitelist for free users, the fact that it tries to connect to port 39288 (and NOT 80), is why the connection is refused.

Please do confirm/suggest alternatives.

Thanks. -S.

Yup. The non-http port is why it is blocked for free accounts.

I tried what systix did and I have a student account.

I am also using pymodm to interface with mlab. I get the the same [Errno 111] Connection refused.

Any ideas how to fix this?

You account has unrestricted internet access, so it should work. Have you tried it in a console that you started since your upgrade?

Here's a help page about MongoDB on PythonAnywhere that hopefully will be useful for anyone with questions about this in the future. Any suggestions for extra stuff we should put on there much appreciated!