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

my join workaround has different behavior on different mongo versions

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.1
    • Component/s: Querying
    • None
    • Environment:
    • ALL
    • Hide

      the structure of documents is below.

      > db.common.findOne(

      {forms:"period"}

      )
      {
      "_id" : ObjectId("5121d883490ef673021d6cb7"),
      "forms" : "period",
      "name" : "2012 - 12",
      "year" : 2012,
      "month" : 12,
      "select" : true,
      "value" : 201212
      }
      >
      > db.dataBankOrganizationStatus.findOne()
      {
      "_id" : ObjectId("50a0cdbe99051833c4ad66c9"),
      "member" : ObjectId("4fe806fae5ce67fd6218dda6"),
      "workflowStatus" :

      { "code" : "005", "name" : "BİLDİRİM YAPILMAYACAK" }

      ,
      "approve" : true,
      "status" :

      { "code" : "003", "name" : "ÜYELİKTEN ÇIKTI" }

      ,
      }
      query_one = {
      "forms": "period",
      "$where":function(){
      var periodID = this._id;
      var result = db.dataBankOrganizationStatus.count({
      "status.code":

      { "$in": ["000", "001","002"] }

      ,
      "workflowStatus.code":

      { "$in": ["000", "001","002", "003","006",] }

      ,
      "period": periodID, //this is join
      "member": ObjectId("projectSpaceLoggedUserId")
      });
      return result > 0;
      }
      }

      "query_two":function(searchObject){
      member = searchObject.member;
      if(member==null)

      { throw "member coul not be found"; }

      periods = [];
      db.dataBankOrganizationStatus.find({
      "status.code":

      { "#in": ["000", "001","002"] }

      ,
      "workflowStatus.code":

      { "#in": ["000", "001","002", "003","006",] }

      ,
      "member": member
      },

      { period:1 }

      ).forEach(function(v)

      { periods.push(v.period); }

      )
      return {
      forms:"common",
      _id:

      { "#in":periods }

      }
      }

      db.common.find(query_one)

      > db.common.find(query_one)
      error: {
      "$err" : "JavaScript execution failed: ReferenceError: db is not defined near 'result = db.dataBankOrganizationStatus.c' (line 3)",
      "code" : 16722
      }

      query = query_two(

      {"member" : ObjectId("4fe806fae5ce67fd6218dda6")}

      )
      { "forms" : "common", "_id" :

      { "#in" : [ ] }

      }

      db.common.find(query)
      no problem here

      Show
      the structure of documents is below. > db.common.findOne( {forms:"period"} ) { "_id" : ObjectId("5121d883490ef673021d6cb7"), "forms" : "period", "name" : "2012 - 12", "year" : 2012, "month" : 12, "select" : true, "value" : 201212 } > > db.dataBankOrganizationStatus.findOne() { "_id" : ObjectId("50a0cdbe99051833c4ad66c9"), "member" : ObjectId("4fe806fae5ce67fd6218dda6"), "workflowStatus" : { "code" : "005", "name" : "BİLDİRİM YAPILMAYACAK" } , "approve" : true, "status" : { "code" : "003", "name" : "ÜYELİKTEN ÇIKTI" } , } query_one = { "forms": "period", "$where":function(){ var periodID = this._id; var result = db.dataBankOrganizationStatus.count({ "status.code": { "$in": ["000", "001","002"] } , "workflowStatus.code": { "$in": ["000", "001","002", "003","006",] } , "period": periodID, //this is join "member": ObjectId("projectSpaceLoggedUserId") }); return result > 0; } } "query_two":function(searchObject){ member = searchObject.member; if(member==null) { throw "member coul not be found"; } periods = []; db.dataBankOrganizationStatus.find({ "status.code": { "#in": ["000", "001","002"] } , "workflowStatus.code": { "#in": ["000", "001","002", "003","006",] } , "member": member }, { period:1 } ).forEach(function(v) { periods.push(v.period); } ) return { forms:"common", _id: { "#in":periods } } } db.common.find(query_one) > db.common.find(query_one) error: { "$err" : "JavaScript execution failed: ReferenceError: db is not defined near 'result = db.dataBankOrganizationStatus.c' (line 3)", "code" : 16722 } query = query_two( {"member" : ObjectId("4fe806fae5ce67fd6218dda6")} ) { "forms" : "common", "_id" : { "#in" : [ ] } } db.common.find(query) no problem here

      I used the following query at mongo version 2.2.3 as a workaround to provide join.
      It worked perfectly.

      but since 2.4.1 the following query give an error message :

      JavaScript execution failed: ReferenceError: db is not defined near 'result = db.dataBankOrganizationStatus.c' (line 3)

      I catched the above error msg on Java Driver aplication side.

      so now I have developed new function for the same puporse (query_two) that calculate and return the query bson object.

      is the above mentioned message an expected behavior for the 2.4.1 and next mongo versions or it is really an error?

      Thanks in advance
      regards,
      Telman

      query_one = {
                          "forms": "period",
                          "$where":function(){
                              var periodID = this._id;
                              var result = db.dataBankOrganizationStatus.count({
                                  "status.code": {
                                      "$in": ["000", "001","002"]
                                  },
                                  "workflowStatus.code": {
                                      "$in": ["000", "001","002", "003","006",]
                                  },
                                  "period": periodID, //this is join
                                  "member": ObjectId("projectSpaceLoggedUserId")
                              });
                              return result > 0;
                          }  
                      }
      
      query_two=function(searchObject){
                          member = searchObject.member;
                          if(member==null){
                              throw "member coul not be found";
                          }
                          periods = [];
                          db.dataBankOrganizationStatus.find({
                              "status.code": {
                                  "#in": ["000", "001","002"]
                              },
                              "workflowStatus.code": {
                                  "#in": ["000", "001","002", "003","006",]
                              },
                              "member": member
                          },{
                              period:1
                          }).forEach(function(v){
                              periods.push(v.period);
                          })                     
                          return {
                              forms:"common",
                              _id:{
                                  "#in":periods
                              }
                          }
                      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            shahbazov telman shahbazov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: