Skip to content

πŸ“œ First steps

Romain edited this page Oct 2, 2022 · 1 revision

1. Connect to the server

First, make sure you have a MongoDB server running. We have previously explained everything about how to get started with MongoDB on this page.

First of all, we will get our server connection address. It will look like this: mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] (official documentation). For example, if you host the MongoDB server on the same machine as your server, it will look like: mongodb://127.0.0.1. If you are on Mongo Atlas, you will find it on your management panel.

This is how it works with Skript:

on script load:
  set {mongosk::server} to mongo server with connection string "mongodb://127.0.0.1" # Replace with your own

2. Select a database

Before selecting a database, you must first have created it. In this example, we have created the mc-server database, and we will use it throughout the tutorial. To select your database, nothing could be easier:

on script load:
  set {mongosk::server} to mongo server with connection string "mongodb://127.0.0.1" # Replace with your own
  set {mongosk::mcserver} to mongo database "mc-server" of {mongosk::server} # Replace with your own

3. Select a collection

This is the last thing you should do. For more simplicity, you just have to add all your collections in variables at the start of your script, to access them more easily when you develop with MongoSK. For the example, we will make two collections: shopItems, shopTransactions.

on script load:
  set {mongosk::server} to mongo server with connection string "mongodb://127.0.0.1"
  set {mongosk::database} to mongo database "mc-server" of {mongosk::server}
  set {mongosk::shopItems} to mongo collection "shopItems" of {mongosk::database}
  set {mongosk::shopTransactions} to mongo collection "shopTransactions" of {mongosk::database}

🏠 Home

πŸƒ What is MongoDB?

πŸš€ Get started!

πŸ“œ First steps


Do you need help? 🦸

If you need help, look at the links in the footer and don't get stuck!

Clone this wiki locally