Difference between revisions of "Mongo"

From Dogtag
Jump to: navigation, search
m (See Also)
m (See Also)
 
Line 78: Line 78:
 
* [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]
 
* [https://mongodb.github.io/mongo-java-driver/3.6/ MongoDB Java Driver 3.6]
 +
* [https://www.geekwire.com/2019/mongodbs-licensing-changes-led-red-hat-drop-database-latest-version-server-os/ MongoDB’s licensing changes led Red Hat to drop the database from the latest version of its server OS]

Latest revision as of 04:00, 7 November 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