This file contains 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.activities.aggregate(([ | |
{ $match: { userId:"u123", ts:{$gt:DATE}, type:"ORDER"}}, | |
{ $group: { _id: "result", count: {$sum: "$total" }}}]) // sum the total of all orders |
This file contains 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.activities.aggregate(([ | |
{ $match: { userId: "u123", ts: { $gt: DATE }}}, // get a time bound set of activities for a user | |
{ $group: { _id: "$type", count: { $sum: 1 }}}]) // group and sum the results by activity type |
This file contains 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.activity.find({ itemId: “301671", // requires a secondary index on timestamp + itemId | |
ts: {“$g”t:1301284969946, | |
“$lt”: 1425657300} }) | |
.sort({ time: -1 }).limit(100) |
This file contains 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.activity.find({ userId: “u123”, | |
ts: {“$g”t:1301284969946, // time bound the query | |
“$lt”: 1425657300} }) | |
.sort({ time: -1 }).limit(100) // sort in desc order |
This file contains 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" : { | |
"source" : "user457", | |
"ts" : NumberLong(324000000) | |
} |
This file contains 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
"storage" : | |
{ | |
"type" : "raw", | |
"config" : | |
{ | |
"id_factory" : | |
{ | |
"type" : "source_time_document", | |
"config" : { } | |
} |
This file contains 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
{ | |
"time_slicing" : | |
{ | |
"type" : "periodic", | |
"config" : { "period" : {"weeks" : 4} } | |
} | |
} |
This file contains 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(), | |
geoCode: 1, // used to localize write operations | |
sessionId: “2373BB…", // tracks activities across sessions | |
device: { id: “1234", // tracks activities across different user devices | |
type: "mobile/iphone", | |
userAgent: "Chrome/34.0.1847.131" | |
} | |
type: "VIEW|CART_ADD|CART_REMOVE|ORDER|…", // type of activity | |
itemId: “301671", // item that was viewed, added to cart, etc. | |
sku: “730223104376", //item sku |
This file contains 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.addTagRange(“inventoryDB.inventory”),{storeId:0},{storeId:100},”west”) | |
- sh.addTagRange(“inventoryDB.inventory”),{storeId:100},{storeId:200},”central”) | |
- sh.addTagRange(“inventoryDB.inventory”),{storeId:200},{storeId:300},”east”) |
This file contains 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.addShardTag(“shard001”,”west”) | |
- sh.addShardTag(“shard002”,”central”) | |
- sh.addShardTag(“shard003”,”east”) |