Agile育成ブログ
未来を変える喜びを
未分類

mongodbインストール


Warning: count(): Parameter must be an array or an object that implements Countable in /home/xs638785/agile-software.site/public_html/wp-content/plugins/rich-table-of-content/functions.php on line 490

リポジトリ(パッケージ)の身元を確認するためにGPGキーをインストール

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

リポジトリ定義を保存

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

aptコマンドでインストール

sudo apt-get -y install mongodb-org

MongoDBの起動

--dbpath オプションを使ってデータの格納先ディレクトリを指定することができます。
 下記の例では、mongoディレクトリをデータ格納先に指定しています。

mongod --dbpath mongo

MongoDBシェル

新しくターミナルを起動しmongoと入力すると

mongo
MongoDB shell version v4.4.16
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("2a40ce55-f0c0-4a15-aa6c-f0030cfa0f68") }
MongoDB server version: 4.4.16
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
---
The server generated these startup warnings when booting: 
        2022-09-17T10:13:34.086+09:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
        2022-09-17T10:13:34.452+09:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2022-09-17T10:13:34.452+09:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
        2022-09-17T10:13:34.452+09:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> db
test
> 1+1
2

新しいデータベースの作成

useを使うことでどのデータベースを使うのか変更できる。

use animalShelter

show dbs

show collections

db.cats.find()

You cannot copy content of this page