[CXX-1138] uncought exception: find_and_update => precondition failed: bson Created: 20/Nov/16  Updated: 21/Nov/16  Resolved: 21/Nov/16

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: 3.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Armin Ball [X] Assignee: J Rassi
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CXX-986 Invalid error handling in find_and_mo... Closed

 Description   

Hey there,
I don't know which statement exactly causes the error. Last time I had this I accidentally changed parameters of the find_and_update - function. Now I finally can reproduce it =).
Hope this is helpful,
Armin

// codesnippets

{{ mongocxx::options::find_one_and_update TheOptions {};
TheOptions.sort(vieOptions);

std::cout
<< "78 - Find:\n" << bsoncxx::to_json(vieFind) << "\n"
<< "78 - Update:\n" << bsoncxx::to_json(vieUpdate) << "\n"
<< "78 - Options.sort:\n" << bsoncxx::to_json(vieOptions)
<< std::endl;

... collJobs.find_one_and_update(vieFind,vieUpdate,TheOptions);}}

src/bson/bson.c:2193 bson_get_data(): precondition failed: bson
process died.

// consol:

78 - Find:
{
"CServer" : {
"error" : false,
"dateEndLeadworker" :

{ "$exists" : true }

,
"dateStartConversion" :

{ "$exists" : false }

}
}

78 - Update:
{
"$set" : {
"CServer" : {
"dateStartConversion" :

{ "$date" : 1479621781745 }

,
"machineConversion" : "MyMachine_f29a8bc8aee611e6a05f0024d74d9538"
}
}
}

78 - Options.sort:
{
"CServer" :

{ "dateEntry" : 1 }

}

// Stacktrace:

{{__GI_raise (sig=6, sig@entry=6)
__GI_abort ()
bson_get_data ()
(anonymous namespace)::find_and_modify(_mongoc_collection_t*, bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value>, _mongoc_find_and_modify_opts_t const*) ()
mongocxx::v_noabi::collection::find_one_and_update(bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value>, bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value>, mongocxx::v_noabi::options::find_one_and_update const&) () }}



 Comments   
Comment by J Rassi [ 21/Nov/16 ]

Hi there, thanks for reporting this issue. I've reproduced your issue and can confirm that this ticket is a duplicate of CXX-986, which has been fixed since 3.0.1 was released. Please upgrade to the latest version of the driver (currently 3.0.3) to obtain the fix.

Please note also that {"CServer": {"dateEntry" : 1}} is an invalid sort object. To request an ascending sort on a field with a name of "dateEntry" in a sub-object of a field with a name of "CServer", you should specify a sort object of { "CServer.dateEntry": 1} instead. If you specify an invalid sort object to mongocxx::collection::find_one_and_update(), it should now correctly throw a mongocxx::operation_exception with an appropriate error message.

Comment by Armin Ball [X] [ 20/Nov/16 ]

for sorting this works:
78 - Options.sort:

{ "dateEntry" : 1 }

// commtented the subdocument.

bsoncxx::document::value valOrderBy = document{}
// << SERVER_KEY_SUBDOCUMENT
// << open_document
<< SERVER_KEY_DATE_ENTRY << ascending
// << close_document
<< finalize;

Generated at Wed Feb 07 22:01:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.