[SERVER-4186] db.collection.save() with documents that contain functions doubling up function names Created: 01/Nov/11  Updated: 11/Jul/16  Resolved: 08/Nov/11

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

Type: Bug Priority: Major - P3
Reporter: Kavi Siegel Assignee: Brandon Diamond
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Win 7 64 bit, Mongo 2.0


Attachments: PNG File mongodbbug.png    
Operating System: Windows
Participants:

 Description   

I suppose this pretty much should speak for its self. At first I thought just the internal function name doubled up, but the custom name would remain when __toString() is called in php. But what it does is take the full internal function name, then re-assign a prefix to it, returning the entire pre-update name as the new function name. Attached is a screenshot, before and after the update I've pasted below.

> a = db.validation.findOne(

{name:'cellPhone'}

)
{
"_id" : ObjectId("4eadb65ba653908619848869"),
"name" : "cellPhone",
"error" : "At least one phone number must be entered",
"code" : function cf_31_f_cf_28f() {},
"errorGroup" : "cellPhone"
}
> a.errorGroup = 'phone'
phone
> db.validation.save(a)
> a = db.validation.findOne(

{name:'cellPhone'}

)
{
"_id" : ObjectId("4eadb65ba653908619848869"),
"name" : "cellPhone",
"error" : "At least one phone number must be entered",
"code" : function cf_32_f_cf_31_f_cf_28f() {
},
"errorGroup" : "phone"
}
> a.code = function code(a){}
function code(a) {
}
> db.validation.save(a)
> a = db.validation.findOne(

{name:'cellPhone'}

)
{
"_id" : ObjectId("4eadb65ba653908619848869"),
"name" : "cellPhone",
"error" : "At least one phone number must be entered",
"code" : function cf_33_f_code(a) {},
"errorGroup" : "phone"
}
> a.errorGroup = 'phone1'
phone1
> db.validation.save(a)
> a = db.validation.findOne(

{name:'cellPhone'}

)
{
"_id" : ObjectId("4eadb65ba653908619848869"),
"name" : "cellPhone",
"error" : "At least one phone number must be entered",
"code" : function cf_34_f_cf_33_f_code(a) {},
"errorGroup" : "phone1"
}
> b = db.validation.findOne(

{name:'businessPhone'}

)
{
"_id" : ObjectId("4eb0036aa65390861984886a"),
"name" : "businessPhone",
"error" : "At least one phone number must be entered",
"code" : function cf_35_f_cf_30_f_cf_28f() {},
"errorGroup" : "phone"
}
> b.run = function(a){}
function (a) {
}
> db.validation.save(b)
> b = db.validation.findOne(

{name:'businessPhone'}

)
{
"_id" : ObjectId("4eb0036aa65390861984886a"),
"name" : "businessPhone",
"error" : "At least one phone number must be entered",
"code" : function cf_36_f_cf_35_f_cf_30_f_cf_28f() {},
"errorGroup" : "phone",
"run" : function cf_37f(a) {
}
}
> delete b.run
true
> db.validation.save(b)
> b = db.validation.findOne(

{name:'businessPhone'}

)
{
"_id" : ObjectId("4eb0036aa65390861984886a"),
"name" : "businessPhone",
"error" : "At least one phone number must be entered",
"code" : function cf_38_f_cf_36_f_cf_35_f_cf_30_f_cf_28f() {},
"errorGroup" : "phone"
}



 Comments   
Comment by Brandon Diamond [ 08/Nov/11 ]

I've implemented a simple fix to resolve this issue. A more comprehensive fix will come when we finish transitioning from spidermonkey to v8.

Comment by auto [ 08/Nov/11 ]

Author:

{u'login': u'', u'name': u'Brandon Diamond', u'email': u'brandon@10gen.com'}

Message: SERVER-4186: Don't re-munge function names
Branch: master
https://github.com/mongodb/mongo/commit/dc82da899b71a77e70e57e66e7f306999e3689e1

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