mongoDB questions

So I’m at the point where I have to start using a real database. A database like mongoDB

There are few things I still don’t understand about mongoDB (and even postgres. Sqlite is fine because the database is just one file that you can manage and call)
How do you create a Database with mongoDB? (command line only)
How do I get the elements in mongodb://[dbuser:dbpassword@]host:port/dbname ?

I know these are some silly questions but I really cant find a place that explains these minor details (that just stop me from proceeding)
Thanks

Can you explain more about this need? What is appropriate depends a lot on specifics like how much data to store, how many servers need to access it, where you want to host it, how you want the data stored (documents vs tables/columns).

Here is a good starting point: https://docs.mongodb.com/guides/

The question you didn’t ask is, where should I host the database?

If its on the same host as your web server software, the connection string will have a host called “localhost”.

There is a free 500MB host offer on https://www.mongodb.com/

This course steps through setting up a Glitch project to connect to the free database: https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/

Theoretically you could install MongoDB on a Glitch project, its not recommended though.

If your storage is fairly small and doesn’t need to be shared with other servers, consider one of the lighter databases that can be hosted inside Glitch, and can be installed via npm packages like nedb, lowdb, SQLite.

1 Like

Thank you for the detailed reply (really really appreciate it).

  1. It’s a discord bot that’s growing too fast. It relies heavily on stored data (i’d say around 500 reads per second and the structures are usually nested -3 properties nesting usually-). I’m right now using Enmap (which uses better-sqlite3) but it relies on RAM (which is a limited thing on Glitch). For now, i need to know how to use it (mongodb or even postgresql) locally. It doesn’t really matter how the data is if its sql or no-sql based to be honest. (I noticed a cool npm package called Keyv that supports postgresql/mongo, but literally once I read const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname'); im 100% lost. Like user and pass and even dbname are kind of (unknown-to-get)

  2. The reason why I want to switch to another database is because Enmap(which again uses sqlite) depends heavily on RAM. and it doesn’t accept external connections (as in if i try to access the database from another external server -like a website-). If you know a better solution, id be thrilled to know about it. What I’m looking for is simply: Solid database that can handle too much data, reads and writes (and that can accept external connections too)
    I’ll check what you sent me, thank you sir very much

This is pretty hard to get on most web hosts, most only allow to host locally (local to the bot server, thats what localhost means), and Glitch has port limitations which also make this hard.

Hosting externally would work. The database on the mongo site is 500MB (storage rather than RAM), but if you pay you can get more storage and more options. There are many other options especially if you are okay with paying, like aws, oracle, IBM, azure, and heaps more, including VPS i.e. host a linux box online and install the database on it (but you’d have to manage it lol).

Those parameters in the connection string are known after you setup the database, and differ depending on how it was installed and configured. to break it down,

mongodb is the protocol, other protocols you might find familiar are ftp, https
user:pass is the username/password to login with on the connection
host is the address of the server where the db is installed, could be a load balancing server, localhost means its on the same machine as you are connecting from.
port is the internet port to connect through, similar to how http uses port 80 and https uses port 443.
dbname is the name of the database, chosen when it is setup, you could have more than one database on the same server, and usually do, for example “admin” and “test” are common.

Usually the connection string is given to you by the same tools that are used to setup the database.

EDIT - I should add, an external database does add additional latency, i.e. a small delay, compared to a local database.

1 Like

What I suggest using is MongoDB Atlas, which is just a cloud version of MongoDB. It’s much easier to configure and it’ll give you the mongodb://[dbuser:dbpassword@]host:port/dbname very easily. See this project on how it works: https://glitch.com/~mongodb-atlas-works. Instructions in the readme2.md file!

1 Like

Well, I can get a paid VPS that is on the same region as the database (like where the 500MB mongo cloud is located, to reduce latency) so Glitch limitations sadly cant stop me at this point (I’ll still use Glitch for my other projects but not this one if im limited).

The guide you sent me is very helpful though, it kind of broke the confusion i had about the connection string and also your explanation. Thank you very much Misha for the advices and help. Much love <3

1 Like

Yeah that’s what I’ll probably use, i’ll still look for a way to have the mongoDB located on a server I own (I won’t have to worry about the database hitting 500MB as well since ill just pay for 100GB storage easily). But since MongoDB Atlas accepts external connections, i might use it for now for learning purposes mainly