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 users where z = 'abc' db.users.remove({z:'abc'})
2. Example database Information
{
"_id" : "" ,
"firstName" : ""
"lastName" : ""
"username" : ""
"password" : "" ,
"role" : { "$ref" : "role" , "$id" : "" }
}
{
"_id" : ""
"role" : ""
}
3. MogonDB Setup
windows7-64 bit
http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2.0.5.zip, I got the latest windows files
Unzip the file to D:\tool\mongodb_2.0.5\bin
create a folder here C:\data\db
Add the bin to my path.
Then I can type the command as follow:
>mongod.exe
or
>mongod.exe -dbpath c:\data\db
ubuntu12.04
>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
add this line to source.list
>sudo vi /etc/apt/sources.list
add this line
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
>sudo apt-get update
>sudo apt-get install mongodb-10gen
The configuration file is here /etc/mongodb.conf
references:
http://hi.baidu.com/luohuazju/blog/item/f256abf3f94a265b342acc54.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_4739.html
https://github.com/krams915/spring-mongodb-tutorial.git
http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
http://static.springsource.org/spring-data/data-document/docs/current/reference/html/
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 users where z = 'abc' db.users.remove({z:'abc'})
2. Example database Information
{
"_id" : "" ,
"firstName" : ""
"lastName" : ""
"username" : ""
"password" : "" ,
"role" : { "$ref" : "role" , "$id" : "" }
}
{
"_id" : ""
"role" : ""
}
3. MogonDB Setup
windows7-64 bit
http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2.0.5.zip, I got the latest windows files
Unzip the file to D:\tool\mongodb_2.0.5\bin
create a folder here C:\data\db
Add the bin to my path.
Then I can type the command as follow:
>mongod.exe
or
>mongod.exe -dbpath c:\data\db
ubuntu12.04
>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
add this line to source.list
>sudo vi /etc/apt/sources.list
add this line
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
>sudo apt-get update
>sudo apt-get install mongodb-10gen
The configuration file is here /etc/mongodb.conf
references:
http://hi.baidu.com/luohuazju/blog/item/f256abf3f94a265b342acc54.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_4739.html
https://github.com/krams915/spring-mongodb-tutorial.git
http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
http://static.springsource.org/spring-data/data-document/docs/current/reference/html/