[SERVER-23171] Bad projection with findAndModify() Created: 16/Mar/16  Updated: 18/Mar/16  Resolved: 18/Mar/16

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

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

Issue Links:
Duplicate
duplicates SERVER-16063 Rewrite findAndModify Closed
Operating System: ALL
Steps To Reproduce:

My failing test :

My object from my collection 'tests':

{
    "_id" : ObjectId("56e81455d98ae5bedd005583"),
    "array" : [
        {
            "field1": "e1f1",
            "field2" : "e1f2",
        },
        {
            "field1": "e2f1",
            "field2": "e2f2",
        },
    ],
}

> db.tests.findAndModify({ query: { _id: ObjectId('56e81455d98ae5bedd005583'), array: { '$elemMatch': { field1: "e2f1" } } }, update: { $set: { 'array.$.field2': 'e2f2' } }, new: false, upsert: false, fields: { 'array.$': 1 } })
{
    "_id" : ObjectId("56e81455d98ae5bedd005583"),
    "array" : [
        {
            
        },
        {
            
        }
    ]
}

The result returns all elements of "array" with empty values.

> db.tests.find({ _id: ObjectId('56e81455d98ae5bedd005583'), array: { '$elemMatch': { field1: "e2f1" } } }, { 'array.$': 1 })
{ "_id" : ObjectId("56e81455d98ae5bedd005583"), "array" : [ { "field1" : "e2f1", "field2" : "e2f2" } ] }

The operation above returns the expected result, but with findAndModify() the result is not the same.

$ mongo --version
MongoDB shell version: 3.0.3

Participants:

 Description   

I try to query, update and project the first element matching the query document with findAndModify(), but the result returns all elements with empty values.



 Comments   
Comment by Kelsey Schubert [ 18/Mar/16 ]

Hi alexandre-ezeeworld,

Thank you for confirming the version of your mongod. The issue you describe was tracked in SERVER-6865, and was fixed as part of refactoring during SERVER-16063. Please consider upgrading to MongoDB 3.2 to take advantage of this fix.

Thank you,
Thomas

Comment by Alexandre [ 16/Mar/16 ]

> db.serverBuildInfo()
{
	"version" : "3.0.3",
	"gitVersion" : "nogitversion",
	"OpenSSLVersion" : "",
	"sysInfo" : "Darwin yosemitevm.local 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49",
	"loaderFlags" : "-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.10",
	"compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -std=c++11 -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -pipe -Werror -O3 -Wno-unused-function -Wno-unused-private-field -Wno-deprecated-declarations -Wno-tautological-constant-out-of-range-compare -Wno-unused-const-variable -Wno-missing-braces -Wno-null-conversion -mmacosx-version-min=10.10 -std=c99",
	"allocator" : "system",
	"versionArray" : [
		3,
		0,
		3,
		0
	],
	"javascriptEngine" : "V8",
	"bits" : 64,
	"debug" : false,
	"maxBsonObjectSize" : 16777216,
	"ok" : 1
}

Comment by Ramon Fernandez Marina [ 16/Mar/16 ]

alexandre-ezeeworld, what version of mongod are you using? Is it 3.0.3 as well? You can find out by running db.serverBuildInfo().

Thanks,
Ramón.

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