[CXX-1225] mongocxx::options::find::sort doesn't work. Created: 21/Feb/17  Updated: 27/Oct/23  Resolved: 21/Feb/17

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

Type: Bug Priority: Major - P3
Reporter: David Assignee: David Golden
Resolution: Works as Designed Votes: 0
Labels: ownership
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Alpine Linux



 Description   

This code below doesn't work on Linux, but act correctly on macOS.

auto v = document{} << "_id" << -1 << finalize;
option.sort(v.view());

and on linux, no error message showed if i write string "-1" instead of -1, and got 'Bad specification error' on macOS.

auto v = document{} << "_id" << "-1" << finalize;
option.sort(v.view());



 Comments   
Comment by David Golden [ 21/Feb/17 ]

I'm glad you figured it out. FWIW, since the options.sort type is bsoncxx::document::view_or_value, you should be able to std::move the sort document and then the option will own the value.

But I'll go ahead and close the ticket.

Comment by David [ 21/Feb/17 ]

It is my fault, because I putted this code inside a if statement.

if (xxx)
{
  auto v = document{} << "_id" << -1 << finalize;
  option.sort(v.view());
}
coll.find(..., option);

So I think the BsonValue is invalid outside the if statement instead of be copied to the find option.
So the code below works for me.

auto v = document{} << "_id" << -1 << finalize;
if (xxx)
  option.sort(v.view());
coll.find(..., option);

Somebody could close this issue.

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