Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- RESTAURANT COLLECTION SINGLE DOCUMENT SCHEMA FOR REFERENCE
- {
- "_id" : ObjectId("5d83eb456e04f8d82b8a8363"),
- "address" : {
- "building" : "2780",
- "coord" : [
- -73.98242,
- 40.579505
- ],
- "street" : "Stillwell Avenue",
- "zipcode" : "11224"
- },
- "borough" : "Brooklyn",
- "cuisine" : "American ",
- "grades" : [
- {
- "date": ISODate("2014-06-10T00:00:00.000Z"),
- "grade": "A",
- "score": 5
- },
- {
- "date": ISODate("2013-06-05T00:00:00.000Z"),
- "grade": "A",
- "score": 7
- },
- {
- "date": ISODate("2012-04-13T00:00:00.000Z"),
- "grade": "A",
- "score": 12
- },
- {
- "date": ISODate("2011-10-12T00:00:00.000Z"),
- "grade": "A",
- "score": 12
- }
- ],
- "name" : "Riviera Caterer",
- "restaurant_id" : "40356018"
- }
- */
- db.getCollection('restaurants').aggregate([
- {
- "$project": {
- "filtered_grades": {
- "$filter": {
- "input": "$grades",
- "as": "grade",
- "cond": { "$in": [ "$$grade.score", [ 12, 2 ] ] }
- }
- }
- }
- }
- ])
- /*
- result
- filters only the selected subdocuments from the array of subdocuments 'grades'
- */
- // just queries
- /*
- db.getCollection('vendors').aggregate([
- {
- "$match": {
- "category": { $in: ['onion'] }
- }
- },
- {
- "$lookup": {
- "from": "products",
- "localField": "products",
- "foreignField": "_id",
- "as": "productObjects"
- }
- },
- {
- "$project": {
- "filtered_products": {
- "$filter": {
- "input": "$productObjects",
- "as": "products",
- "cond": { "$in": [ "$$products.productname", ["onion","tomato"] ] }
- }
- }
- }
- },
- {
- "$project": {
- "prods":"$filtered_products" ,
- "total":{$size:"$filtered_products"}
- }
- }
- ]);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement