발췌: https://docs.mongodb.com/manual/reference/sql-comparison/


* 용어의 차이


RDBMS

 MongoDB

 TABLE

 COLLECTION

 ROW

 BSON DOCUMENT

 COLUMN

 FIELD

 INDEX

 INDEX 

 PRIMARY KEY

 OBJECT_ID FILED

 TABLE JOINS (RELATIONSHIP)

 EMBEDDED, LINKING 


* 쿼리 명령어 차이

 SQL

 MongoDB

 CREATE TALE test (a int, b int)

 db.createCollection("test")

 INSERT INTO test VALUES (3,5)

 db.table.insert({name:3, age:5})

 SELECT name, age FROM test

 db.table.find({}, {name:1, age:1})

 SELECT * FROM test

 db.table.find()

 SELECT * FROM testWHERE age=34

 db.table.find({age:34})

 SELECT a,b FROM testWHERE age=34

 db.table.find({age:34}, {a:1,b:1})

 SELECT * FROM test WHERE age=34 ORDER BY name

 db.table.find({age:34}).sort({name:1})

 SELECT * FROM test WHERE age>34

 db.table.find({'age':{$gt:34}})

 SELECT * FROM test WHERE age<34

 db.table.find({'age':{$lt:34}})

 SELECT * FROM test WHERE name LIKE"%Joe%"

 db.table.find({name:/Joe/})

 SELECT * FROM test WHERE name LIKE "Joe%"

 db.table.find({name:/^Joe/})

 SELECT * FROM test WHERE age>34 AND age<=40

 db.table.find({'age':{$gt:34,$lte:40}})

 SELECT * FROM test  ORDER BY name DESC

 db.table.find().sort({name:-1})

 SELECT * FROM test WHERE a=1 and b='q'

 db.table.find({a:1,b:'q'})

 SELECT * FROM test LIMIT 10 SKIP 20

 db.table.find().limit(10).skip(20)

 SELECT * FROM test WHERE a=1 or b=2

 db.table.find( { $or : [ { a : 1 } , { b : 2 } ] } )

 SELECT * FROM test LIMIT 1

 db.table.findOne()

 SELECT DISTINCT last_name FROM test 

 db.table.distinct('last_name')

 SELECT COUNT(*y) FROM test 

 db.table.count()

 SELEC COUNT(*y) FROM test where AGE > 30

 db.table.find({age: {'$gt': 30}}).count()

 SELECT COUNT(AGE) from test 

 db.table.find({age: {'$exists':true}}).count()

 CREATE INDEX myindexname ON test (name)

 db.table.ensureIndex({name:1})

 CREATE INDEX myindexname ON test(name,ts DESC)

 db.table.ensureIndex({name:1,ts:-1})

 EXPLAIN SELECT * FROM users WHERE z=3

 db.table.find({z:3}).explain()

 UPDATE users SET a=1 WHERE b='q'

 db.table.update({b:'q'}, {$set:{a:1}},false,true)

 UPDATE users SET a=a+2 WHERE b='q'

 db.table.update({b:'q'}, {$inc:{a:2}},false,true)

 DELETE FROM users WHERE z="abc"

 db.table.remove({z:'ab'});


SQL SELECT 쿼리에 대하여 궁금하다면? [바로가기]

RDBMS Scheme를 몽고DB Data modeling으로 변경 [바로가기]

'Developments > MongoDB' 카테고리의 다른 글

pymongo 도움말  (0) 2016.08.07
몽고DB 스키마 디자인  (0) 2016.08.05
몽고DB 관리툴  (0) 2016.07.30
몽고DB 명령어  (0) 2016.07.29
몽고DB 윈도우에 설치  (0) 2016.07.28

+ Recent posts