[SERVER-3219] $inc can sometimes rename existing fields when they end in '0' Created: 08/Jun/11  Updated: 09/Jun/11  Resolved: 09/Jun/11

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

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Steps to reproduce:

> db.test.foo.insert({"a":

{"c0":1}

, 'c':2})
> db.test.foo.find(

{"c":2}

)
{ "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

{ "c0" : 1 }

, "c" : 2 }
> db.test.foo.update(

{"c":2}

, {'$inc':{'a.b0':1}})
> db.test.foo.find(

{"c":2}

)
// So far, so good
{ "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

{ "b0" : 1, "c0" : 1 }

, "c" : 2 }

//Things go off the rails. This should add a new field, 'c00'
> db.test.foo.update(

{"c":2}

, {'$inc':{'a.c00':1}})
> db.test.foo.find(

{"c":2}

)

// Notice the 'c0' key has been changed to 'c00'. This should have added a new field.
{ "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

{ "b0" : 1, "c00" : 2 }

, "c" : 2 }

// This works as expected.
> db.test.foo.update(

{"c":2}

, {'$inc':{'a.cc':1}})
> db.test.foo.find(

{"c":2}

)
{ "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

{ "b0" : 1, "cc" : 1, "c00" : 2 }

, "c" : 2 }
>



 Comments   
Comment by Eliot Horowitz (Inactive) [ 09/Jun/11 ]

See SERVER-3218

Comment by gsk [ 09/Jun/11 ]

> db.foo.remove()

> db.foo.insert(

{"a1":1, "c":1}

)

> db.foo.update(

{"c":1}

, {$set:{"a00001":1}})
> db.foo.findOne()

{ "_id" : ObjectId("4df02d8521564c165c35681f"), "a00001" : 1, "c" : 1 }

> db.foo.update(

{"c":1}

, {$set:{"a0000000001":1}})
> db.foo.findOne()

{ "_id" : ObjectId("4df02d8521564c165c35681f"), "a0000000001" : 1, "c" : 1 }

> db.foo.update(

{"c":1}

, {$set:{"a00000000011":1}})
> db.foo.findOne()
{
"_id" : ObjectId("4df02d8521564c165c35681f"),
"a0000000001" : 1,
"a00000000011" : 1,
"c" : 1
}

so i guess the character of '0' be ignored by mongodb

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