본문 바로가기

[mongodb] db 복제 1.복제 해 와서 붙여넣을 mongodb에 접속한다. 2. 다음 명령을 실행한다. db.copyDatabase(fromdb, todb, fromhost, username, password)Copies a database from a remote host to the current host or copies a database to another database within the current host. db.copyDatabase() wraps the copydb command and takes the following arguments: Parameter Type Description fromdb string The name of the source database. todb string The na.. 더보기
[mongodb] Replica Set A서버 1234 port에서 돌고있는 mongod가 있는 상태에서 5678 port mongod를 같이 돌리려고 한다. master : Aslave : B 1. A서버와 B서버 동일하게 conf파일을 복사하여 포트번호를 5678로 수정하고 replica 이름과 host도 설정해준다. (master의 host로 설정한다, name은 동일하게) 2. conf파일이 2개가 생겼으므로 mongod를 실행할 때 --config 옵션을 주어야 하는데 귀찮으므로 shell 파일을 따로 생성한다. ~~~1234.start~~~5678.start 3. 기존 db폴더의 이름을 db_1234로 바꾸고 mkdir db_5678하여 하나 더 생성해준다 (빈 디렉터리만 생성하면 된다) 4. A, B 서버에서 mongod를 실행하.. 더보기
[mongodb] $text Indexes 설정하기 $text Index는 mongodb 버전 2.4 이상부터 사용 가능하다. collection에 한 개만 사용 할 수 있다. db.collection.ensureIndex( { [컬럼명]:"text", [컬럼명2]:"text", ....[컬럼명n]:"text" }, { name: "[인덱싱이름]" } )위와 같이 인덱스를 생성해준다. 쿼리는 db.collection.find({ "$text" : { "$search" : "\"세월호 침몰\""}}) ----> like 검색db.collection.find({ "$text" : { "$search" : "세월호 침몰"}}) ----> or 검색 (세월호 or 침몰)db.collection.find({ "$text" : { "$search" : "세월호 -침.. 더보기