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"}
}
}
)