问题描述
我正在尝试在没有大量高级代码和自定义的情况下实现此类目标。如果该解决方案在深度嵌套#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/exception/exception.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <iostream>
class MongoDB {
public:
MongoDB() :
client{mongocxx::uri{"mongodb://localhost:27017"}},db{client["dbted"]},coll{db["movie"]}
{}
mongocxx::cursor all() { return coll.find({}); }
private
mongocxx::client client;
mongocxx::database db;
mongocxx::collection coll;
static mongocxx::instance inst;
};
mongocxx::instance MongoDB::inst{};
int main() {
try {
MongoDB db;
std::cout << "Connected successfully\n";
for(auto doc : db.all()) {
std::cout << bsoncxx::to_json(doc) << '\n';
}
} catch(const std::exception& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
return 1;
}
}
值的情况下确实能很好地工作,即使它涉及编写许多高级和自定义代码,也可以。
T
我尝试了一些解决方案,其中涉及为该通用部分编写自定义类型转换器,当然,该转换器不适用于深度嵌套的@JsonSerializable()
class Response<T> { // T can be every type from native types,to nested generic custom classes
final int code;
final T data;
Response({
this.code,this.data,});
}
值。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)