Hi,
I just tried this out with the following code:
```
#include <iostream>
#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/options/find.hpp>
#include <mongocxx/uri.hpp>
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;
int main(int, char**) {
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
auto db = conn["test"];
auto col = db["regex"];
{
std::string prefix = "prefix "; //prefix with trailing space
bsoncxx::builder::basic::document query_regex{};
auto regex = bsoncxx::types::b_regex("^" + prefix, "");
query_regex.append(bsoncxx::builder::basic::kvp("text", regex));
auto cursor = col.find(query_regex.view());
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
}
```
And the following two documents in the "test" database and "regex" collection:
```
> use test
switched to db test
> db.regex.find();
{ "_id" : ObjectId("59e9c5b3966816952ccdb2b6"), "text" : "prefix" }
{ "_id" : ObjectId("59e9c5ce966816952ccdb2b7"), "text" : "prefix " }
{ "_id" : ObjectId("59e9c886966816952ccdb2b8"), "text" : "prefixfootball" }
{ "_id" : ObjectId("59e9c889966816952ccdb2b9"), "text" : "prefix football" }
>
```
And the output (As expected) is:
```
derick@singlemalt:/tmp $ ./foo
{ "_id" : { "$oid" : "59e9c5ce966816952ccdb2b7" }, "text" : "prefix " }
{ "_id" : { "$oid" : "59e9c889966816952ccdb2b9" }, "text" : "prefix football" }
```
From what I can see, you're not doing anything out of the ordinary and using b_regex as you'd expect. It doesn't add any default wildcards. Of course, that your pattern "^prefix " matches also things like "prefix football" (but not prefixfootball) as you're only anchoring to the start of the string.
Could you share a full code snippet (that compiles) and which data your script returns, what is in the collection, and what you expected?
cheers,
Derick