Giter Club home page Giter Club logo

redis_csharp's Introduction

Poo_2-2

Data manipulation with C Sharp

Status: 🚀 Finished

AboutTech StackInstallationUsageContact

About

EN = This project is intended as a grade for the college's Object Oriented Programming II subject, The purpose of this project is to access the MongoDB database with the C Sharp programming language and consult and change the data with the same.

PT = Esse projeto tem como finalidade como nota para a matéria de Programação Orientada a Objetos II da faculdade, o objetivo da prova e acessar o banco de dados em MongoDB com a linguagem de programação C Sharp e consultar e alterar os dados com a mesma.

Tech Stack

csharp Badge 

Installation

To Install this project, follow the steps above:

# Install MongoDB Community Server
https://www.mongodb.com/try/download/community

# Install .Net
https://dotnet.microsoft.com/en-us/download

# Install Visual Studio Code
https://code.visualstudio.com/

# Add extension C# in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp

Usage

To use this project, follow the steps above:

# Start Serve MongoDB
$ sudo systemctl start mongod

# Check status from MongoDB
$ sudo systemctl status mongod

# create DB "testdb"
$ mongo testdb

# insert some values ​​into the database
db.cars.insert({name: "Audi", price: 52642})
db.cars.insert({name: "Mercedes", price: 57127})
db.cars.insert({name: "Skoda", price: 9000})
db.cars.insert({name: "Volvo", price: 29000})
db.cars.insert({name: "Bentley", price: 350000})
db.cars.insert({name: "Citroen", price: 21000})
db.cars.insert({name: "Hummer", price: 41400})
db.cars.insert({name: "Volkswagen", price: 21600})

# Add MongoDB.Driver in project through the terminal
dotnet add package MongoDB.Driver --version 2.15.1

# Run the program
dotnet run

# MongoDB find all documents

using MongoDB.Driver;
using MongoDB.Bson;

namespace FindAll
{
    class Program
    {
        static void Main(string[] args)
        {
            var dbClient = new MongoClient("mongodb://127.0.0.1:27017");
            IMongoDatabase db = dbClient.GetDatabase("testdb");

            var cars = db.GetCollection<BsonDocument>("cars");
            var documents = cars.Find(new BsonDocument()).ToList();

            foreach (BsonDocument doc in documents)
            {
                Console.WriteLine(doc.ToString());
            }
        }
    }
}

# MongoDB insert document

using MongoDB.Driver;
using MongoDB.Bson;

namespace InsertDocument
{
    class Program
    {
        static void Main(string[] args)
        {
            var dbClient = new MongoClient("mongodb://127.0.0.1:27017");

            IMongoDatabase db = dbClient.GetDatabase("testdb");

            var cars = db.GetCollection<BsonDocument>("cars");

            var doc = new BsonDocument
            {
                {"name", "BMW"},
                {"price", 34621}
            };

            cars.InsertOne(doc);
        }
    }
}

# MongoDB delete document

using MongoDB.Driver;
using MongoDB.Bson;

namespace DeleteDocument
{
    class Program
    {
        static void Main(string[] args)
        {
            var dbClient = new MongoClient("mongodb://127.0.0.1:27017");

            IMongoDatabase db = dbClient.GetDatabase("testdb");

            var cars = db.GetCollection<BsonDocument>("cars");
            var filter = Builders<BsonDocument>.Filter.Eq("name", "BMW");

            cars.DeleteOne(filter);
        }
    }
}

Contact

Made with ❤️ by Igor Silva, get in touch!

Email Badge  LinkedIn Badge 


redis_csharp's People

Contributors

igorsilvam avatar flaviojoliveira 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.