Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JoeyBurzynski/973811fbbce6c4d40870cd5701911990 to your computer and use it in GitHub Desktop.
Save JoeyBurzynski/973811fbbce6c4d40870cd5701911990 to your computer and use it in GitHub Desktop.
MongoDB Aggregation Pipeline: CalTrend
db.getCollection("caltrend").aggregate(
// Pipeline
[
// Stage 1
{
$project: {
_id : 1,
vendor_part_number: "$PartNumber",
vendor: "$BrandLabel",
name: { $concat: [ {$arrayElemAt:[{$split: ["$Note" , " - "]}, 0]}, " ", "$Description.Text" ] },
color_description: {$arrayElemAt:[{$split: ["$Note" , " - "]}, 1]},
color_id: {$arrayElemAt:[{$split: ["$PartNumber" , "-"]}, 1]},
color_insert: {$arrayElemAt:[{$split: [{$arrayElemAt:[{$split: ["$Note" , " - "]}, 1]} , " Insert"]}, 0]},
color_trim: { $or: [ {$arrayElemAt:[{$split: [{$arrayElemAt:[{$split: ["$Note" , " with "]}, 1]} , " Trim"]}, 0]}, {$arrayElemAt:[{$split: [{$arrayElemAt:[{$split: ["$Note" , " - "]}, 1]} , " Insert"]}, 0]} ]},
product_id: {$arrayElemAt:[{$split: ["$Note" , " - "]}, 0]},
image_url: "$DigitalAssets.URL",
weight: "$Package.Weight",
height: "$Package.Height",
length: "$Package.Length",
width: "$Package.Width",
price_sheet_number: "$Pricing.PriceSheetNumber",
price_wholesale: "$Pricing.Price",
price_retail: { $multiply: [ "$Pricing.Price", 1.20 ] }
}
},
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment