Mongodb 如何将bsoncxx::builder::basic::文档复制到另一个?

Mongodb 如何将bsoncxx::builder::basic::文档复制到另一个?,mongodb,c++11,bson,mongo-cxx-driver,Mongodb,C++11,Bson,Mongo Cxx Driver,是否有任何方法可以安全地将bsoncxx文档复制到另一个文档。 在下面的代码中,我无法做到这一点 class DocClass { private: bsoncxx::builder::basic::document m_doc; public: bsoncxx::builder::basic::document& copy(bsoncxx::builder::basic::document& obj) { obj = m_doc; //N

是否有任何方法可以安全地将bsoncxx文档复制到另一个文档。 在下面的代码中,我无法做到这一点

class DocClass
{
private:
    bsoncxx::builder::basic::document m_doc;
public:
    bsoncxx::builder::basic::document& copy(bsoncxx::builder::basic::document& obj)
    {
        obj = m_doc; //Not allowed
        //Error C2280   attempting to reference a deleted function
    }
};
即使在复制之后,也不应对对象造成任何伤害。 请帮忙

谢谢,
Shibin

如果要复制bsoncxx::document::value,可以从其视图中构造一个新的:

bsoncxx::document::value foo = ...;
bsoncxx::document::value bar{foo.view()};

bsoncxx::builder::basic::文档仅可移动,不可复制。但是,您可以使用
view()
方法从构建器获取对基础文档的视图,该方法可能会根据您的用例对您有所帮助。尽管如此,您仍然只能从生成器中提取一次,因此如果需要多个文档,您必须依赖于构造第二个
文档::值。

这里似乎有点混乱。代码和问题的编写就像您想要复制一个
bsoncxx::document::value
,但您正在传递
bsoncxx::builder::basic::document
。这些是非常不同的事情。你真的想模仿建设者吗?是的,我想模仿建设者。[我发现构建器在默认情况下是不可复制的]仍然有办法做到这一点吗?所以,让我问一个显而易见的问题。为什么要复制生成器?基本上我正在升级mongodb驱动程序。所以在客户端代码中是这样的:
void GetBasicPropertiesToFetch(const wstring&collectionName,CMongoBsonBuilder&bsonfildStoreTurn){//需要将类成员(builder)复制到bsonfildStoreTurn}
CMongoBsonBuilder是使用BSONObjBuilder的包装类。现在,使用bsoncxx::builder::basic::document代替BSONObjBuilder。