Chapter 0: Aggregation structure

Hi
I was trying out the codes from the lecture.

db.solarSystem.aggregate([{
  "$match": {
    "atmosphericComposition": { "$in": [/O2/] },
    "meanTemperature": { $gte: -40, "$lte": 40 }
  }
}, {
  "$project": {
    "_id": 0,
    "name": 1,
    "hasMoons": { "$gt": ["$numberOfMoons", 0] }
  }
}], { "allowDiskUse": true});

Gives output { “name” : “Earth”, “hasMoons” : true }

But I dont get any output for the following code

    db.solarSystem.aggregate([{ 
    	$match: {
    		atmosphericComposition: { $in : [/02/]},
    		meanTemperature: { $gte: -40, $lte: 40}
    	}
    }, 
    {
    	$project: { _id: 0, name: 1, hasMoons: { $gt: [ "$numberOfMoons", 0]}}
    }], { allowDiskUse: true })

There is no major difference between those two pieces of code. One is using the quotation and the other without. Any idea?

I found the bug. I needed to use “O2” but instead I have “02”.

Thanks anyway.

1 Like