Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19387

Query validity not checked before execution

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 3.0.3
    • 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}} ]);

    Description

      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.

      Attachments

        1. enron.zip
          108.43 MB

        Activity

          People

            sam.kleinman Sam Kleinman (Inactive)
            pratik229 Pratik Patel
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: