Mongo

From Dogtag
Revision as of 23:36, 22 February 2020 by Edewata (talk | contribs) (See Also)

Jump to: navigation, search

Installation

$ dnf install mongodb-server

Starting Server

$ systemctl start mongod

Command-Line Client

Connecting to Database

To connect to a local database:

$ mongo <database>

To connect to a remote database:

$ mongo "mongodb+srv://<hostname>/<database>" --username <username>

Displaying Database Info

To display database name:

MongoDB> db

To display database version:

MongoDB> db.version()

Listing Collections

MongoDB> show collections

Creating a Collection

MongoDB> db.createCollection("users")

Removing a Collection

MongoDB> db.users.drop()

Listing Documents

MongoDB> db.users.find()

Creating a Document

MongoDB> db.users.insertOne({
    uid: "testuser",
    name: "Test User"
})

Removing a Document

MongoDB> db.users.remove({"uid": "testuser"})

Java Client

Installation

$ dnf install mongo-java-driver

See Also