GithubHelp home page GithubHelp logo

mongodblinux's Introduction

mongoDB guide for GNU+Linux with free Atlas

The creators of MongoDB grant a free server to be able to use their technology, in our case we are going to take advantage of it to learn and do tests.

First we must register on their website: First image

We give our project a name and specify the language that we are going to use (in our case Java): Second Image

We choose the free plan: Third image

We select the server provider and the location: Fourth image

We just have to wait for it to finish starting and we can use our new server: Fifth image

That's all friends! we add our beautiful IP in the white list and we can access it through Java or Mongo Shell: Sixth image

If you want to learn how to connect through java, take a look at the code in this repository but here is some sample code. But be careful, to start using mongo in Java we must install its JAR, in my case through POM.xml

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
    <version>4.2.0</version>
</dependency>

Okay! First we have to add the ConnectionString of our server:

ConnectionString connString = new ConnectionString(
                    "mongodb+srv://USERINMYSERVER:PASSWORD@URLOFMYSERVER/?retryWrites=true&w=majority"
            );

In my case it would be like this:

ConnectionString connString = new ConnectionString(
                "mongodb+srv://dbUser:[email protected]/?retryWrites=true&w=majority"
        );

We add the options with MongoClientSettings:

MongoClientSettings settings = MongoClientSettings.builder()
                .applyConnectionString(connString)
                .retryWrites(true)
                .build();

And we apply them:

MongoClient mongoClient = MongoClients.create(settings);

And finally we specify the database and the collection:

MongoDatabase database = mongoClient.getDatabase("nueva");
MongoCollection<Document> collection = database.getCollection("profes");

Y con esto y un bizcocho (as we say in Catalonia) we would already have it, we can use collection.deleteOne to delete or collection.insertOne to add a new document. If you want to learn more, you have some code examples from this repository or in the MongoDB documentation.

mongodblinux's People

Contributors

julioferrero avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.