mongodb(1)Some mongodb concept and installation on my servser
mongodb(1)Some mongodb concept and installation on my servser
1. Comparison between SQL and MongoDB
I am a new guy for mongoDB, coming from a SQL-background.
MySQL term Mongo term/Concept
database database
table collection
index index
row BSON document
column BSON field
join embedding and linking
primary key _id field
group by aggregation
BSON is a binary-encoded serialization of JSON-like documents. http://bsonspec.org/
SQL Statement Mongo Statement
create table users db.createCollection("users");
alter table users add ...
insert into users values ... db.users.insert({a:3,b:5})
select a,b from users db.users.find({},{a:1,b:1})
select * from users db.users.find()
select a,b from users where age =33 db.users.find({age:33},{a:1,b:1})
select * from users where age=33 order by name db.users.find({age:33}).sort({name:1})
select * from users where name like "%sillycat%" db.users.find({name:/sillycat/})
select * from users where name like "sillycat%" db.users.find({name:/^sillycat/})
select * from users where age>33 and age <=40 db.users.find({'age':{>:33,$lte:40}})
select * from users order by name desc db.users.find().sort({name:-1})
select * from users where a=1 and b='q' db.users.find({a:1,b:'q'})
select * from users limit 10 skip 20 db.users.find().limit(10).skip(20)
select * from users where a=1 or b=2 db.users.find({$or : [ {a:1},{b:2} ] } )
select * from users limit 1 db.users.findOne()
select count() from users db.users.count()
select count() from users where age > 30 db.users.find({age:{'$gt':30}}).count()
update users set a=1 where b='q' db.users.update({b:'q'},{$set:{a:1}},false,true)
delete from