[SERVER-13015] 2.6.0-rc0: Update that violates sparse index is not done, generates no complaint. Created: 03/Mar/14  Updated: 07/Mar/14  Resolved: 04/Mar/14

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

Type: Bug Priority: Major - P3
Reporter: William Cross Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-13036 2.6 shell silently ignores duplicate ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

When updating a value to another value that it cannot take because of a unique index, the update fails, but no error is generated.

This is bad b/c the update method found the document, and would have performed the update without the index, but does not complain. Users may think the update worked awesomely, but be wrong.

Steps to Reproduce:

> db.moo.drop()
> db.moo.insert({a: 1})
> db.moo.insert({a: 2})
> db.moo.find()
{ "_id" : ObjectId("53150cb99b76858b68c2631a"), "a" : 1 }
{ "_id" : ObjectId("53150cbc9b76858b68c2631b"), "a" : 2 }
> db.moo.ensureIndex({a: 1}, {unique: true})
> db.moo.update({a: 2}, {a: 1})
> db.moo.find()
{ "_id" : ObjectId("53150cb99b76858b68c2631a"), "a" : 1 }
{ "_id" : ObjectId("53150cbc9b76858b68c2631b"), "a" : 2 }
> db.getLastError()
null
>



 Comments   
Comment by William Cross [ 04/Mar/14 ]

Verified. Thanks for the help with this!

Comment by William Cross [ 03/Mar/14 ]

Other possible weird stuff: I have some other mongod's running on this box.

will@will-macbook-air:~/mongodb/bin/2.6$ ps ax | grep mongod
  821   ??  S     48:09.19 mongod --logpath /data/db/mongod.log --fork
26286   ??  S      0:47.14 ./mongod --port 27018 --dbpath /data/db255/ --logpath /data/db255/mongod.log --fork
26339 s004  S+     0:43.14 ./mongod --logpath /data/db26/mongod.log --port 27019 --dbpath /data/db26
26923 s007  S+     0:00.01 grep mongod
will@will-macbook-air:~/mongodb/bin/2.6$

Comment by William Cross [ 03/Mar/14 ]

I have two v2.6 mongo shells open in different tabs in iTerm 2.

Comment by William Cross [ 03/Mar/14 ]

You can grep for version() above.

Comment by William Cross [ 03/Mar/14 ]

My full shell output:

will@will-macbook-air:~/mongodb/bin/2.6$ ./mongo 27019
MongoDB shell version: 2.6.0-rc0
connecting to: 27019
Server has startup warnings:
Thu Feb 27 17:27:59.108 [initandlisten]
Thu Feb 27 17:27:59.108 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> db.moo.insert({a: 1})
> db.moo.insert({a: 2})
> db.moo.find()
{ "_id" : ObjectId("53150cb99b76858b68c2631a"), "a" : 1 }
{ "_id" : ObjectId("53150cbc9b76858b68c2631b"), "a" : 2 }
> db.moo.ensureIndex({a: 1}, {unique: true})
> db.moo.update({a: 2}, {a: 1})
> db.moo.find()
{ "_id" : ObjectId("53150cb99b76858b68c2631a"), "a" : 1 }
{ "_id" : ObjectId("53150cbc9b76858b68c2631b"), "a" : 2 }
> db.getLastError()
null
> version()
2.6.0-rc0
> db.moo.update({a: 2}, {a: 1})
> db.getLastError()
null
> db.moo.update({a: 2}, {a: 1}); db.getLastErrorObj()
{
	"err" : "E11000 duplicate key error index: 27019.moo.$a_1  dup key: { : 1.0 }",
	"code" : 11001,
	"n" : 0,
	"connectionId" : 21,
	"ok" : 1
}
> db.moo.update({a: 2}, {a: 1}); db.getLastError()
E11000 duplicate key error index: 27019.moo.$a_1  dup key: { : 1.0 }
>

Comment by William Cross [ 03/Mar/14 ]

Sending more info from the shell. We're dealing with the possibility that I've got a weird shell situation, and are debugging that.

Comment by Scott Hernandez (Inactive) [ 03/Mar/14 ]

You do not appear to be using the 2.6 shell (note that you do not have a WriteResult), nor calling getLastError() immediately after the write so something is suspect in your example/environment.

I cannot reproduce this. Here is my output:

> db.a.find()
> db.a.save({_id:1, a:1})
WriteResult({ "nInserted" : 1 })
> db.a.save({_id:1, a:1})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
> db.a.ensureIndex({a:1}, {unique:true})
WriteResult({ "nInserted" : 1 })
> db.a.save({_id:1, a:1})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
> db.a.save({_id:3, a:1})
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 0,
	"nModified" : 0,
	"writeError" : {
		"code" : 11000,
		"errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.a.$a_1  dup key: { : 1.0 }"
	}
})
> db.a.update({a:1}, {a:2})
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 0,
	"nModified" : 0,
	"writeError" : {
		"code" : 11000,
		"errmsg" : "E11000 duplicate key error index: test.a.$a_1  dup key: { : 2.0 }"
	}
})

We can re-open if you can provide more detail about your environment and reproduction case.

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