0

I'm struggling to get a valid conversion of my qstring to whatever kvp needs inside mongo...

I tried

std::string_view k(documentKey.toStdString().c_str());//, documentKey.size()); // tried adding size as wll
std::string_view v(documentId.toStdString().c_str());//, documentId.size());

and then:

auto doc = mCollection.find(make_document(kvp(k, v)));

But I keep on getting empty results. If I type directly k/v as "someKey", "someValue" it works just fine. But I can't figure out how to convert it from one to another... any ideas?

TIA

Dariusz
  • 960
  • 13
  • 36

1 Answers1

0

kvp can be built with two strings, so if .toStdString() returns a valid string this should work for you:

std::string docKey = documentKey.toStdString();
std::string docId = documentId.toStdString();
auto doc = mCollection.find(make_document(kvp(docKey, docId)));

Please keep in mind that if the _id is automatically generated by mongo you'll need to use an ObjectId type instead.

SPM
  • 405
  • 1
  • 5
  • 16
  • Hey I managed to get it to work. Ended up being a quite interesting issue as I could not use toStdString() due to the way mongo was taking the arg. I had to pre-declare it above. I'll post an answer with how I solved it. – Dariusz Jun 19 '20 at 18:19