コンテンツにスキップ

Apache CouchDB チートシート

Apache CouchDB - Document Database

Apache CouchDBは、ドキュメント指向のNoSQLデータベースで、ドキュメントにJSONを、APIにHTTPを、クエリにJavaScriptのMapReduceを使用します。マルチバージョン同時実行制御により、ACIDセマンティクスと最終的な一貫性を提供します。

[No text to translate] ```bash # Add CouchDB repository curl -L https://couchdb.apache.org/repo/keys.asc | sudo apt-key add - echo "deb https://apache.jfrog.io/artifactory/couchdb-deb/ focal main" | sudo tee /etc/apt/sources.list.d/couchdb.list

Update package index

sudo apt update

Install CouchDB

sudo apt install couchdb

Configure CouchDB during installation

Choose standalone or clustered mode

Set admin password

Start CouchDB service

sudo systemctl start couchdb sudo systemctl enable couchdb

Check status

sudo systemctl status couchdb

Verify installation

curl http://127.0.0.1:5984/

```bash
# Add EPEL repository
sudo yum install epel-release

# Add CouchDB repository
sudo tee /etc/yum.repos.d/couchdb.repo << EOF
[couchdb]
name=CouchDB
baseurl=https://apache.jfrog.io/artifactory/couchdb-rpm/el7/\$basearch/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://couchdb.apache.org/repo/keys.asc
EOF

# Install CouchDB
sudo yum install couchdb

# Start CouchDB service
sudo systemctl start couchdb
sudo systemctl enable couchdb

# Check status
curl http://127.0.0.1:5984/
```[No text to translate]
```bash
# Pull CouchDB image
docker pull couchdb:latest

# Run CouchDB container
docker run -d \
  --name couchdb \
  -p 5984:5984 \
  -e COUCHDB_USER=admin \
  -e COUCHDB_PASSWORD=password \
  -v couchdb-data:/opt/couchdb/data \
  couchdb:latest

# Check CouchDB
curl http://admin:password@localhost:5984/

# Docker Compose setup
cat > docker-compose.yml << EOF
version: '3.8'
services:
  couchdb:
    image: couchdb:latest
    container_name: couchdb
    ports:
      - "5984:5984"
    environment:
      - COUCHDB_USER=admin
      - COUCHDB_PASSWORD=password
    volumes:
      - couchdb-data:/opt/couchdb/data
      - couchdb-config:/opt/couchdb/etc/local.d
    restart: unless-stopped

volumes:
  couchdb-data:
  couchdb-config:
EOF

docker-compose up -d
```[No text to translate]
```bash
# Download CouchDB
wget https://downloads.apache.org/couchdb/source/3.3.3/apache-couchdb-3.3.3.tar.gz

# Extract
tar -xzf apache-couchdb-3.3.3.tar.gz
cd apache-couchdb-3.3.3

# Install dependencies (Ubuntu/Debian)
sudo apt install build-essential pkg-config erlang \
  libicu-dev libmozjs-78-dev libcurl4-openssl-dev

# Configure and compile
./configure
make release

# Install
sudo cp -r rel/couchdb /opt/
sudo useradd -d /opt/couchdb couchdb
sudo chown -R couchdb:couchdb /opt/couchdb

# Create systemd service
sudo tee /etc/systemd/system/couchdb.service << EOF
[Unit]
Description=Apache CouchDB
After=network.target

[Service]
Type=simple
User=couchdb
ExecStart=/opt/couchdb/bin/couchdb
Restart=always

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl start couchdb
sudo systemctl enable couchdb
```[No text to translate]
```bash
# Check CouchDB status
curl http://localhost:5984/

# Get server information
curl http://localhost:5984/_up

# Get all databases
curl http://localhost:5984/_all_dbs

# Get server stats
curl http://localhost:5984/_stats

# Get active tasks
curl http://localhost:5984/_active_tasks

# Get cluster membership
curl http://localhost:5984/_membership

# Get node information
curl http://localhost:5984/_node/_local/_stats

# Authentication
curl -u admin:password http://localhost:5984/

# Using session authentication
curl -X POST http://localhost:5984/_session \
  -H "Content-Type: application/json" \
  -d '{"name": "admin", "password": "password"}'

# Get current user
curl http://localhost:5984/_session
```[No text to translate]
```bash
# Get configuration
curl http://admin:password@localhost:5984/_node/_local/_config

# Get specific configuration section
curl http://admin:password@localhost:5984/_node/_local/_config/httpd

# Set configuration value
curl -X PUT http://admin:password@localhost:5984/_node/_local/_config/httpd/bind_address \
  -d '"0.0.0.0"'

# Delete configuration value
curl -X DELETE http://admin:password@localhost:5984/_node/_local/_config/httpd/bind_address

# Restart CouchDB
curl -X POST http://admin:password@localhost:5984/_node/_local/_restart

# Common configuration locations
# /opt/couchdb/etc/local.ini
# /opt/couchdb/etc/local.d/

# Example local.ini configuration
cat > /opt/couchdb/etc/local.d/custom.ini << EOF
[httpd]
bind_address = 0.0.0.0
port = 5984

[ssl]
enable = true
cert_file = /path/to/cert.pem
key_file = /path/to/key.pem

[log]
level = info

[couchdb]
max_dbs_open = 500
EOF
```[No text to translate]
```bash
# Create database
curl -X PUT http://admin:password@localhost:5984/mydb

# Check if database exists
curl -I http://admin:password@localhost:5984/mydb

# Get database information
curl http://admin:password@localhost:5984/mydb

# Get database stats
curl http://admin:password@localhost:5984/mydb/_stats

# List all databases
curl http://admin:password@localhost:5984/_all_dbs

# Delete database
curl -X DELETE http://admin:password@localhost:5984/mydb

# Compact database
curl -X POST http://admin:password@localhost:5984/mydb/_compact

# Get database security
curl http://admin:password@localhost:5984/mydb/_security

# Set database security
curl -X PUT http://admin:password@localhost:5984/mydb/_security \
  -H "Content-Type: application/json" \
  -d '{
    "admins": {
      "names": ["admin"],
      "roles": ["admin"]
    },
    "members": {
      "names": ["user1"],
      "roles": ["user"]
    }
  }'

# Get database changes
curl http://admin:password@localhost:5984/mydb/_changes

# Get changes with filter
curl http://admin:password@localhost:5984/mydb/_changes?include_docs=true&limit=10

# Continuous changes feed
curl http://admin:password@localhost:5984/mydb/_changes?feed=continuous
```[No text to translate]
http://admin:password@localhost:5984/mydb[No text to translate]

Note: Some sections were empty or contained no text to translate, so they were left as-is.