MongoDB
문서
로그 파일 삭제
# /var/log/mongodb/mongod.log sudo cp /dev/null mongod.log
도커에서 인증 활성화
docker run
$ docker run -d --rm --name mongo_remote_container \ -p 27000:27017 \ -e MONGO_INITDB_ROOT_USERNAME=admin \ -e MONGO_INITDB_ROOT_PASSWORD=secret_password \ mongo \ mongod --auth
docker run -d --rm --name mongo_remote_container \ -e MONGODB_ADMIN_USER=admin \ -e MONGODB_ADMIN_PASS=secret_admin_pa$$ \ -e MONGODB_APPLICATION_DATABASE=mytestdatabase \ -e MONGODB_APPLICATION_USER=testuser \ -e MONGODB_APPLICATION_PASS=testpass \ -p 27000:27017 aashreys/mongo-auth:latest \
db.auth('admin', 'secret_admin_pa$$')
mongodb find
regex
- snippet.json
db.getCollection('wine_collection').find({'name_ko': {'$regex' : ".*마르케시 디 바롤로, 사르마싸.*"}})
elemMatch
- snippet.json
db.getCollection('wine_collection').find({"varieties" : {'$elemMatch' : {"$eq": "네비올로"}}})
링크
특정 필드를 가지고 있는 문서 조회
- snippet.db
db.getCollection('stock_company').find({'daily_updated': {'$exists': true}}).count()
특정 필드 삭제
$unset
사용
multi: true
를 지정하여 여러 문서에 적용
db.getCollection('stock_company').update({}, {'$unset': {'daily_updated': ''}}, {'multi': true})
여러 필드를 삭제하는 경우
db.getCollection('stock_company').update({}, {'$unset': {'daily_updated': '', 'second_field': ''}}, {'multi': true})