Skip to content

Instantly share code, notes, and snippets.

@astropanic
Last active December 12, 2015 00:39
Show Gist options
  • Save astropanic/4685547 to your computer and use it in GitHub Desktop.
Save astropanic/4685547 to your computer and use it in GitHub Desktop.
An example of the MongoDB aggregation framework
use wlw;
db.wlw.drop();
heading1 = { _id: 10001, name: "Schrauben" , company_counts: { "de":0, "at":9 }, keywords: ["Metall", "Gewinde", "Konstruktion"] };
heading2 = { _id: 10002, name: "Rohre" , company_counts: { "de":1, "at":3 }, keywords: ["Metall", "Profil" , "Konstruktion"] };
heading3 = { _id: 10003, name: "Holzballen", company_counts: { "de":3, "at":0 }, keywords: ["Holz" , "Bau" , "Konstruktion"] };
db.wlw.insert(heading1);
db.wlw.insert(heading2);
db.wlw.insert(heading3);
db.wlw.find();
//db.wlw.aggregate([ {}, {}, {} ]);
db.wlw.aggregate([{$match:{"name":"Schrauben"}}]);
{
"result" : [
{
"_id" : 10001,
"name" : "Schrauben",
"company_counts" : {
"de" : 0,
"at" : 9
},
"keywords" : [
"Metall",
"Gewinde",
"Konstruktion"
]
}
],
"ok" : 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment