Aggregation Structure and Syntax

Hi There,

When i’ve tried to execute the following command which is provided in the “aggregation_structure.js” handout, i’ve got the following error.

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

Error:
image

Please help me out to execute this.

Hi,

It looks like you are trying to access a solarSytem collection in a solarSystem database, which is not correct. Please note that the solarSystem collection is in the aggregations database.

José Carlos

Hi, I’m having the same issue - the aggregate I’m running is not returning any results. Maybe I have a misspelling?

I’m connected to the atlas cluster that the course provided a link for.

MongoDB Enterprise Cluster0-shard-0:PRIMARY> use aggregations
switched to db aggregations
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

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

For anyone else who may stumble upon this,
i found the result in a different topic, the 02 must be the letter O not the number 0