mongoDB

ii  mongodb   1:2.4.9-1ubuntu2   amd64   object/document-oriented database (metapackage)
Arch Linux
yay mongodb-bin
yay mongodb-tools
Drivers
Console

How to start server

cd mongodb-linux-x86_64-2.0.6
bin/mongod --dbpath /var/tmp/mongodb
/etc/mongodb.conf

port = 27017

sudo systemctl status mongodb

sudo systemctl stop mongodb

/var/log/mongodb/mongodb.log

PHP

sudo apt install php-pear php7.2-dev
sudo pecl install mongodb
/etc/php/7.2/cli/php.ini
extension=mongodb.so
Ubuntu 16.04
sudo apt install php-pear php7.0-dev
sudo apt install pkg-config

sudo pecl install mongodb
/etc/php/7.0/cli/php.ini

extension=mongodb.so
mongo-php-driver

mongodb-mongo-php-driver-1.1.4-3-gdb58b36.tar.gz

$ phpize
$ ./configure
$ make
$ sudo make install

Then add
extension=mongo.so
to /etc/php5/cli/php.ini
& /etc/php5/apache2/php.ini

Python

PyMongo 1.5.1

ii  python-pymongo   2.2-4   amd64    Python interface to the MongoDB document-oriented database
sudo apt install python3-pymongo

yay python-pymongo

Perl

    sudo cpan MongoDB
libmodule-install-perl
libclass-meta-perl
libany-moose-perl
libfile-slurp-perl
libboolean-perl
Ruby

# gem install mongo
# gem install bson_ext
Java

mongo-java-driver
mongo-java-driver-3.0.3.jar

C#

mongodb-csharp


$ mongo
MongoDB shell version: 3.2.9
connecting to: test
> db
test
> show dbs
city_db	0.203125GB
exampleDb	0.203125GB
local	0.078125GB
> use city_db
switched to db city_db
> db
city_db
> show collections
saitama
system.indexes
> db.saitama.find ()
{ "_id" : ObjectId("538d2fc65f87ddfac4108581"), "key" : "t1161", "name" : "さいたま", "population" : 58143, "date_mod" : "2001-9-12" }
{ "_id" : ObjectId("538d2fc65f87ddfac4108582"), "key" : "t1162", "name" : "所沢", "population" : 62987, "date_mod" : "2001-10-9" }
> exit
bye

Arch Linux
# pacman -S mongodb

# pacman -S mongodb-tools

# pacman -S php-mongodb

# pacman -S python-pymongo

$ yaourt -Sb ruby-mongo

$ yaourt -Sb ruby-bson_ext

# systemctl start mongodb

設定ファイル
/etc/mongodb.conf


バックアップ
$ mongodump --host localhost --db city_db

$ mongodump --gzip --db city_db

リストア
mongorestore --host localhost --db city_db ./dump/city_db

$ mongorestore --gzip --db city_db --dir dump/city_db/


HTTP Status Interface

/usr/lib/systemd/system/mongodb.service

ExecStart=/usr/bin/mongod --quiet --rest --config /etc/mongodb.conf

http://localhost:28017/

Remote からの接続

mongo admin --host example.com:27017 -u scott -p tiger123

スーパーユーザーの作成方法

> use admin
switched to db admin
> db.createUser({user: "scott",pwd: "tiger123",roles: ["userAdminAnyDatabase","readWriteAnyDatabase","dbAdminAnyDatabase"]})
Successfully added user: {
	"user" : "hapo",
	"roles" : [
		"userAdminAnyDatabase",
		"readWriteAnyDatabase",
		"dbAdminAnyDatabase"
	]
}
> 
result_aa

outarea_aa
outarea_bb
outarea_cc
outarea_dd
outarea_ee
outarea_ff
outarea_gg
outarea_hh

Return

Dec/19/2023 AM 08:15