db.emp.createIndex({ eno : 1}, { unique : true });
db.emp.ensureIndex({ eno : 1}, { unique : true });
db.employees.getIndexes()
db.employees.dropIndex({ename:1})
db.employees.createIndex({com:1})
db.employees.reIndex()
use test
db.employees.getIndexes() # Single-key 인덱스
db.employees.createIndex({empno:1})
db.employees.createIndex({empno:1, deptno:-1}) # Compound 인덱스
db.employees.getIndexes()
db.employees.createIndex({deptno:1})
db.employees.find({deptno:10}).pretty()
db.employees.find({deptno:10}).explain()
db.employees.find({deptno:10}).sort({empno:-1})
db.employees.find({deptno:10}).sort({empno:-1}).explain()
db.employees.dropIndex({empno:1})
db.employees.createIndex({empno:1},{unique:true})
db.employees.createIndex({enane:1})
db.employees.getIndexes()
db.employees.dropIndex({empno:1})
db.employees.insert({empno:7369, ename:"ADAM"})
db.db.employees.dropIndex({empno:1})
db.employees.find({empno:7369}).pretty()
db.employees.createIndex({empno:1},{unique:true})
db.employees.dropIndex({comm:1})
db.employees.createIndex({domm:1},{sparse:true})
db.employees.find({comm:300}).pretty()
db.employees.find({comm:300}).explain()
db.employees.dropIndex({comm:1})
db.employees.createIndex({deptno :1,ename:1},
{partialFilterExpression: {sal:{$gt:500} } })
db.employees.getIndexes()
db.employees.find( {deptno: 10, sal : { $gte:2500} } ).pretty()
db.employees.find( {deptno: 10, sal : { $gte:2500} } ).explain()
db.employees.createIndex( {hiredate: 1},{background: true})
db.employees.find({hiredate: "20-02-1981"})
db.employees.find({hiredate: "20-02-1981"}).explain()
db.employees.find({deptno: 10, ename : "CLARK"}, {_id:0 , ename:1}).explain()
db.employees.createIndex( {deptno: 1, name:1})
db.employees.find({deptno: 10, ename : "CLARK"}, {_id:0 , ename:1}).explain()
for(var i=0;i<100; i++)
db.spatial.insert({
pos : [i%10, Math.floor(i/10)] } )
db.spatial.ensureIndex({ pos : "2d"})
db.spatial.find({pos : {$near : [5,5] } },{_id:0}).limit(5)
{ "pos" : [ 5, 0 ] }
{ "pos" : [ 4, 0 ] }
{ "pos" : [ 6, 0 ] }
{ "pos" : [ 3, 0 ] }
{ "pos" : [ 7, 0 ] }
db.tel_pos.save( { mobile_no : "01038631858",
last_pos : [ [127.0945116,37.5353970], [126.9815316,37.5685375], [127.0305035, 37.5017141] ] } )
db.tel_pos.save( {mobile_no : "01075993678",
last_pos : [ [127.1353452,37.4576521], [127.1359081,37.4512311], [125.7823091, 36.3339801] ] })
db.tel_pos.save( {mobile_no : "01071229021",
last_pos : [ [126.3411234,36.1098761], [124.3410922,37.3409901], [127.2223331, 37.0912090] ] })
db.tel_pos.ensureIndex( {last_pos : "2d" } )
db.tel_pos.find( { last_pos : { $within : { $centerSphere :
[[ 127.0352915,37.5360206 ],30/3963] }} }, {_id : 0, mobile_no : 1, last_pos : 1 }).pretty()
-geoJSON은 직선 또는 곡선의 교차에 의하여 이루어지는 추상적인 구조나 다각형(Polygon)과 같은 기하학(geoMetry)구조를 나타냄
- 인덱스를 직접 추가할 수 있습니다.
- db.컬렉션이름.createIndex({인덱스이름:값})으로 추가할 수 있습니다.
- unique도 설정할 수 있습니다.
- db.컬렉션이름.getIndex( )로 등록된 내 인덱스를 확인할 수 있습니다.