From Dogtag
Revision as of 01:36, 13 September 2019 by Edewata (talk | contribs) (Edewata moved page MongoDB to Mongo without leaving a redirect)

Jump to: navigation, search


$ 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


$ dnf install mongo-java-driver

See Also