글

라벨이 mongodb인 게시물 표시

How to connect to remote MongoDB server

How to connect to remote MongoDB server ~ $  sudo vi /etc/mongod.conf # network interfaces net:   port: 27017   bindIp: 127.0.0.1   bindIpAll: true ~ $ sudo service mongod restart

Import csv tsv file into MongDB

When the csv or tsv file has headerline csv $ mongoimport -d <database> -u <username> -c <collection> --type csv --headerline --file <filename> tsv $ mongoimport -d <database> -u <username> -c <collection> --type tsv --headerline --file <filename> When the csv or tsv file doesn't have headerline and set field type $ mongoimport -d <database> -u <username> -c <collection> --type tsv --columnsHaveTypes --fields "name.string(),register.boolean(),phone.int32()"  --file <filename> https://docs.mongodb.com/manual/reference/program/mongoimport/

자주쓰는 MongoDB 명령어

# remove a document on MongoDB $ db.<collection>.remove({ _id: ObjectId("id")}); # update a document  on MongoDB # change name to "bao" $ db.<collection>.update({ _id: ObjectId("") }, { $set: { name: "bao" }}); # update multi documents  on MongoDB # find all documents which type is not "t" and then change their type to "n" $ db.<collection>.update({ type: { $ne: 't' }}, { $set: { type : ''n" }}, { multi: true });

Backup And Restore MongoDB 몽고DB 백업

Backup  mongodump --host mongodb1.example.net --port 3017 --username user --password "pass" --out /opt/backup/mongodump-2013-10-24 Restore mongorestore --host mongodb1.example.net --port 3017 --username user --password 'pass' /opt/backup/mongodump-2013-10-24 https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/

Install MongoDB on Linux

Install guide https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition Start MongoDB sudo service mongod start ~ $ mongo MongoDB shell version v4.0.4 connecting to: mongodb://127.0.0.1:27017 Implicit session: session { "id" : UUID("9d29ae49-0a6b-4b7a-b6b2-2b4b569362d6") } MongoDB server version: 4.0.4 Server has startup warnings:   2018-11-18T22:44:34.298+0900 I STORAGE   [initandlisten]   2018-11-18T22:44:34.298+0900 I STORAGE   [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2018-11-18T22:44:34.298+0900 I STORAGE   [initandlisten] **           See http://dochub.mongodb.org/core/prodnotes-filesystem 2018-11-18T22:44:35.355+0900 I CONTROL   [initandlisten]   2018-11-18T22:44:35.355+0900 I CONTROL   [initandlisten] ** WARNING: Access control is not enabled for the datab...

Search text on MongoDB (single, two fields)

var skip = 0 ; var limit = 5 ; var search = "apple" ; // search text in one field (title) News . find ({ title: { $regex: search } }). sort ({ pubDate: - 1 }) . skip ( skip ). limit ( limit ). exec ( function ( err , data ) { // TODO }); // search text in two fields (title and description) News . find ({ $or: [{ title: { $regex: search } }, { description: { $regex: search } }] }) . sort ({ pubDate: - 1 }). skip ( skip ). limit ( limit ). exec ( function ( err , data ) { // TODO });

mongoDB admin 권한 설정방법 How to enable access control for mongo DB

** WARNING: Access control is not enabled for the database. ** Read and write access to data and configuration is unrestricted. 해결방법 Solution 요약 : mongoDB를 설치하면 기본적으로 admin이라는 db가 생성됩니다. 이 admin db에 앞으로 생성할 db와 user를 관리할 수 있는 administrator 계정을 생성합니다. 그리고 나서 administrator 계정을 통해 작업할 db와 그 db에 접근 가능한 user 계정을 만듭니다. 이후 user 계정으로 접속해 db 작업을 진행합니다. // How to enable access control for  mongo DB $ mongo connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.10 Server has startup warnings: 2018-01-12T09:03:22.199+0900 I CONTROL  [initandlisten] 2018-01-12T09:03:22.199+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-01-12T09:03:22.199+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted. 2018-01-12T09:03:22.199+0900 I CONTROL  [initandlisten] // db list > show dbs ad...