This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongos> sh.addShardTag('shard0000', 'recent') | |
mongos> sh.addShardTag('shard0001', 'tier 2') | |
mongos> sh.addShardTag('shard0002', 'tier 2') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MongoDB shell version: 2.4.6 | |
connecting to: 127.0.0.1:30004/test | |
// | |
mongos> sh.status() | |
--- Sharding Status --- | |
sharding version: { | |
"_id" : 1, | |
"version" : 3, | |
"minCompatibleVersion" : 3, | |
"currentVersion" : 4, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sh.setBalancerState (false) | |
use config | |
#adjust lower bound of the "current" range | |
db.tags.update( { "tag" : "current" }, { "$set" : { "min._id" : 201208140000032543 } } ) | |
#adjust upper bound of the "archive" range | |
db.tags.update( { "tag" : "archive" }, { "$set" : { "max._id" : 201208140000000000 } } ) | |
sh.setBalancerState(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#add two shards | |
sh.addShardTag ("shard0000", "archive") | |
sh.addShardTag ("shard0001", "recent") | |
#shard database and collection, use "_id" as shard key | |
sh.enableSharding("mydb") | |
sh.shardCollection("mydb.mydata", { "_id" : 1 }) | |
#define tag ranges | |
#first tag range: from the beginning of time until 1 Jan 2013, everything goes to "archive" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.{ pg: 0.06370586088275128, | |
airportCode: "ATL", | |
airportState: "Georgia", | |
airportStateId: "GA", | |
airportCity: "Atlanta, GA" }, | |
2.{ pg: 0.04987817077679942, | |
airportCode: "ORD", | |
airportState: "Illinois", | |
airportStateId: "IL", | |
airportCity: "Chicago, IL" }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var reduce = function(airportId, values) { | |
var pg = 0 | |
, diff = 0 | |
, prs = {} | |
, prevpg = 0 | |
, beta = 0.9 | |
, totalNodes = 0; | |
for (var i in values) { | |
// Retrieve the previous pagerank and the probability matrix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map = function() { | |
// For each node that is reachable from this node, give it the | |
// appropriate portion of my pagerank | |
for (var toNode in this["value"]["prs"]) { | |
emit(toNode, {totalNodes : 0.0 | |
, pg : this["value"]["prs"][toNode] * this["value"]["pg"] | |
, prs : {} | |
, diff : 0.0 | |
, prevpg : 0.0}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id" : "12478", | |
"value" : { | |
"pg" : (1 / NUM_OF_AIRPORTS_IN_DB), | |
"prs" : { | |
"12892" : (NUM_OF_FLIGHTS_FROM_12478_TO_12892 / NUM_OF_FLIGHTS_FROM_12478), | |
... | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id" : ObjectId("51bf..."), | |
... | |
"origAirportId" : 12478, | |
"origStateId" : "NY", | |
... | |
"destAirportId" : 12892, | |
"destStateId" : "CA", | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.products.insert({last_viewed:["bike","cd","game","bike","book"]}) | |
db.products.findOne() | |
{ | |
"_id" : ObjectId("51ff97d233c4f2089347cab6"), | |
"last_viewed" : [ | |
"bike", | |
"cd", | |
"game", | |
"bike", | |
"book" |