Difference between revisions of "Mongo"

From Dogtag
Jump to: navigation, search
m (Edewata moved page MongoDB to Mongo without leaving a redirect)
m (See Also)
Line 77: Line 77:
 
* [https://tecadmin.net/install-mongodb-on-fedora/ How to Install MongoDB on Fedora]
 
* [https://tecadmin.net/install-mongodb-on-fedora/ How to Install MongoDB on Fedora]
 
* [https://docs.mongodb.com/ecosystem/drivers/java/ Java MongoDB Driver]
 
* [https://docs.mongodb.com/ecosystem/drivers/java/ Java MongoDB Driver]
 +
* [https://mongodb.github.io/mongo-java-driver/3.6/ MongoDB Java Driver 3.6]

Revision as of 03:47, 13 September 2019

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