快速例子学习mongodb的mapreduce
mongodbjavamongomapreduce
map和reduce是十分有用的操作,特别是在NOSQL中.本文简单小结下?
在mongodb中对mapreduce的操作,以及在JAVA中如何操作.?
1 启动mongodb?
?? mongo启动即可?
2 建立db?
?? use test?
3 加点记录?
?? > book1 = {name : "Understanding JAVA", pages : 100}?
> book2 = {name : "Understanding JSON", pages : 200}?
?? > db.books.save(book1)?
> db.books.save(book2)?
? 继续加?
? > book = {name : "Understanding XML", pages : 300}?
> db.books.save(book)?
> book = {name : "Understanding Web Services", pages : 400}?
> db.books.save(book)?
> book = {name : "Understanding Axis2", pages : 150}?
> db.books.save(book)?
4? 先来做MAP,这里是先归类,按页数去划分分类,如下:?
??
- >?var?map?=?function()?{??
- var?category;??
- if?(?this.pages?>=?250?)???