[SERVER-9369] my join workaround has different behavior on different mongo versions Created: 17/Apr/13  Updated: 10/Dec/14  Resolved: 19/Apr/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: telman shahbazov Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

telman@telman:~$ uname -a
Linux telman 3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25 18:26:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
telman@telman:~$ mongo --version
MongoDB shell version: 2.4.1
telman@telman:~$


Issue Links:
Related
is related to SERVER-8104 MapReduce on Sharded System Can Bypas... Closed
Operating System: ALL
Steps To Reproduce:

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

Participants:

 Description   

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
                        }
                    }
                }



 Comments   
Comment by Daniel Pasette (Inactive) [ 19/Apr/13 ]

This change was required for security. See: SERVER-8104

Comment by Daniel Pasette (Inactive) [ 19/Apr/13 ]

The ability to use global properties such as "db" was removed in 2.4. Please see the release notes:

http://docs.mongodb.org/manual/release-notes/2.4/#additional-limitations-for-map-reduce-and-where-operations

Generated at Thu Feb 08 03:20:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.