Query validity not checked before execution

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.0.3
    • Component/s: Usability
    • None
    • ALL
    • Hide

      Execute the following query on attached dataset (enron.zip):

      db.messages.aggregate([
      {$unwind:"$headers.To"},
      {$group:{_id:

      {id: '$_id', from:'$headers.From'}

      , to:{$addToSet: '$headers.To'}}},
      {$unwind:"$to"},
      {$project:{_id:0,from:"$_id.from",to:1}},
      {$group:{_id:

      {from:"$from",to:"$to"}

      ,count:{$sum:1}}},
      {$sort:{"count":-1}}
      ]);

      Show
      Execute the following query on attached dataset (enron.zip): db.messages.aggregate([ {$unwind:"$headers.To"}, {$group:{_id: {id: '$_id', from:'$headers.From'} , to:{$addToSet: '$headers.To'}}}, {$unwind:"$to"}, {$project:{_id:0,from:"$_id.from",to:1}}, {$group:{_id: {from:"$from",to:"$to"} ,count:{$sum:1}}}, {$sort:{"count":-1}} ]);
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I was executing the below query on the enron dataset provided as part of MongoDB university training.

      m101:PRIMARY> db.messages.aggregate([ {$unwind:"$headers.To"},  {$group:{_id:{id
      : '$_id', from:'$headers.From'}, to:{$addToSet: '$headers.To'}}}, {$unwind:"$to"
      }, {$project:{_id:0,from:"$_id.from",to:1}}, {$group:{_id:{from:"$from",to:"$to"
      },count:{$sum:1}}}, {$sort:{"count":-1}} ]).explain();
      

      It came back after full 13 seconds complaining that there is a syntax errorL

      2015-07-14T05:59:44.438-0400 E QUERY TypeError: Object #<Object> has no method 'explain'
      at (shell):1:271
      m101:PRIMARY>

      In my opinion validity of the query should be checked first before actually executing the query. Here it seems to have executed the query and then tried to execute the unavailable "explain" method which makes it look like an expensive mistake.

      Apologies if similar jira already exists or if this is filed under wrong project.

            Assignee:
            Sam Kleinman (Inactive)
            Reporter:
            Pratik Patel
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: