Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1574820
  • 博文数量: 399
  • 博客积分: 8508
  • 博客等级: 中将
  • 技术积分: 5302
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-14 09:28
个人简介

能力强的人善于解决问题,有智慧的人善于绕过问题。 区别很微妙,小心谨慎做后者。

文章分类

全部博文(399)

文章存档

2018年(3)

2017年(1)

2016年(1)

2015年(69)

2013年(14)

2012年(17)

2011年(12)

2010年(189)

2009年(93)

分类: 架构设计与优化

2015-04-26 16:46:19

mongod --master --dbpath=database/

mongod --port 8888 --slave --source=127.0.0.1:27017 --dbpath=database_slave_1/

mongo shell

>  db.tickets.find()

>  db.tickets.drop()

> db.tickets.count()

> db.tickets.getIndexes()

> db.getProfilingLevel()

> db.setProfilingLevel(2)

> db.getProfilingLevel()

> map = function() { emit(this.schoold_id, {a:[this]}) };

> reduce = function(key, values) { result = {a:[]}; values.forEach( function(v) { result.a = v.a.concat(',').concat(result.a) } ); return result }

> final = function(key, value) {  return value }

> tickets.mapReduce(map, reduce, {finalize: final})


> db.tickets.aggregate( [{ $match: {school_bucket: "1" } }, { $group: { _id: "$school_number", school_name: {$first: "$school_name"}, sample_ticket:{$first: "$ticket_number"}, "count": {"$sum":1 } }}, {$sort: {count: -1}} , {$limit:3}])

>  db.tickets.aggregate( { $match: {school_bucket: "1" } }, { $group: { _id: "$school_number", school_name: {$first: "$school_name"}, sample_ticket:{$first: "$ticket_number"}, "count": {"$sum":1 } }}, {$sort: {count: -1}} , {$limit:5},{$cursor: { batchSize:1}})

>  db.tickets.aggregate( [{ $match: {school_bucket: "1" } }, { $group: { _id: "$school_number", school_name: {$first: "$school_name"}, sample_ticket:{$first: "$ticket_number"}, "count": {"$sum":1 } }}, {$sort: {count: -1}} ], {$limit:5},{$cursor: { batchSize:1}})

> db.tickets.aggregate(  [{ $match: {school_bucket: "1" } }, { $group: { _id: "$school_number", school_name: {$first: "$school_name"}, sample_ticket:{$first: "$ticket_number"}, "count": {"$sum":1 } }},  {$sort: {count: -1}} ], {explain:true}, {cursor: {batchSize:100}})

> db.tickets.aggregate( { $match: {school_bucket: "1" } }, { $group: { _id: "$school_number", school_name: {$first: "$school_name"}, sample_ticket:{$first: "$ticket_number"}, "count": {"$sum":1 } }}, {$sort: {count: -1}} ).pretty()

> db.tickets.aggregate( { $match: {school_bucket: "1" } }, { $group: { _id: "$school_number", school_name: {$first: "$school_name"}, sample_ticket:{$first: "$ticket_number"}}})

> db.tickets.aggregate( { $match: {school_bucket: "1" } },  { $group: { _id: "$school_number", school_name: {$first: "$school_name"}}})

> db.tickets.aggregate( { $match: {school_bucket: "1" } },  { $group: { _id: "$school_number", school_name: {$first: "$school_name"}}})

> db.tickets.aggregate( { $match: {school_bucket: "1" } })

> db.tickets.aggregate( { $group: { _id: "$school_number", school_name: {$first: "$school_name"}}})

> db.system.profile.find().pretty()

> db.tickets.aggregate(
{ $group:

    { _id: "$school_number",
      school_name: {$first: "school_name"}
    }
}
)
阅读(1213) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~