简体   繁体   English

如何在Ubuntu中安装和使用mongodb c ++驱动程序?

[英]How to install and use mongodb c++ driver in Ubuntu?

Official documentation seems to lack step by step instructions for installing and usage of c++ driver. 官方文档似乎缺少有关安装和使用c ++驱动程序的分步说明。 This thread and the answer seem more promissing. 这个线索和答案似乎更加挑衅。 But still I'm not sure what I'm doing wrong, because I can not $ locate client/dbclient.h in Ubuntu , as if mongo driver was not installed. 但是我仍然不确定自己在做什么,因为我无法在Ubuntu $ locate client/dbclient.h ,就像没有安装mongo驱动程序一样。 So, this is what I did: 所以,这就是我所做的:

  1. Dowloaded driver at this link -ok 在此链接下载驱动程序-ok
  2. Unzipped the archive - ok 解压缩存档-确定
  3. installed scons like so $ sudo apt-get install scons 像这样安装scons $ sudo apt-get install scons
  4. Did $ scons and then 做了$ scons然后
  5. sudo $ scons install sudo $ scons install
  6. opened /etc/ld.so.conf file and added /usr/local/lib 打开/etc/ld.so.conf文件并添加/usr/local/lib

After all these steps I still can not locate client/dbclient.h in my system. 完成所有这些步骤后,我仍然无法在系统中找到client/dbclient.h It seems as if I missed something. 好像我错过了什么。 Besides, when I get to the stage when the library gets installed, I want to read the core of the library, because in tiny tutorials on the Web I can not find everything I want (I guess because of the lack of full-fledged tutorials similar to those of Python ). 此外,当我进入安装库的阶段时,我想阅读该库的核心,因为在Web上的小教程中,我找不到想要的一切(我想是因为缺少完整的教程)类似于Python )。 So, can you also, please, advise what library files I should look at to learn the api of functions, that I will be using? 因此,您能否也请建议我将使用哪些库文件来学习函数的api?

EDIT 编辑

And this official link seems to be outdated, because $ scons --full install results in error message No such option: --full . 而且此官方链接似乎已过时,因为$ scons --full install导致错误消息No such option: --full The lack of tutorials, outdated documentation and rather steep learning curve, IMHO, make usage of c++ rather problematic. 缺少教程,过时的文档以及陡峭的学习曲线恕我直言,这使c ++的使用出现了很多问题。

EDIT 编辑

Well, it seems like this doc is not just outdated, but incorrect, since it sdould be: 好吧,似乎这个文档不仅仅是过时的,而且是不正确的,因为它应该是:

scons --prefix=/usr/include install.

However, even though I specify --prefix=/usr/include I can not locate any mongo files inside this folder after installation process. 但是,即使我指定了--prefix=/usr/include ,安装过程后我也无法在此文件夹中找到任何mongo文件。 I face exactly the very same problem as a guy in this thread . 我面对的正是同样的问题,因为在这一个家伙线程 I guess, my final question should be "Does anybody in the world use mongodb in C++?" 我猜,我的最后一个问题应该是“世界上是否有人在C ++中使用mongodb?”

EDIT 编辑

If I try to do 如果我尝试去做

$ sudo git clone git@github.com:mongodb/mongo-cxx-driver.git

Then I get Could not read from remote repository etc. It seems like they did everything to prevent using mongdb in c++. 然后我Could not read from remote repository等。似乎他们做了一切工作,以防止在c ++中使用mongdb。

EDIT : This posting gets a lot of traffic, but describes how to build the now-officially-out-of-date "Legacy C++" Driver. 编辑 :这篇文章获得了大量的流量,但是描述了如何构建现在正式过期的“旧版C ++”驱动程序。 The Legacy C++ driver has been obsoleted by the new C++11 driver. 旧版C ++驱动程序已被新的C ++ 11驱动程序淘汰。 The new C++11 driver should be the first choice when writing a client application in C++ that will communicate with MongoDB. 使用C ++编写将与MongoDB通信的客户端应用程序时,新的C ++ 11驱动程序应该是首选。 Information on how to build the new C++11 driver is available here: 有关如何构建新的C ++ 11驱动程序的信息,请参见:

https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver) https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(新驱动程序)

Modern instructions for building the driver can be found on the GitHub Wiki page for the C++ driver. 可在C ++驱动程序的GitHub Wiki页面上找到构建驱动程序的现代说明。 Please see the following: 请参阅以下内容:

https://github.com/mongodb/mongo-cxx-driver/wiki/Download-and-Compile-the-Legacy-Driver https://github.com/mongodb/mongo-cxx-driver/wiki/Download-and-Compile-the-Legacy-Driver

https://github.com/mongodb/mongo-cxx-driver/wiki/Tutorial https://github.com/mongodb/mongo-cxx-driver/wiki/教程

A note from a year on: many of the links above are now obsolete and point forwards to these github pages . 一年后的注释:上面的许多链接现在已过时,并指向这些github页面 That page is more generic than the responders above seem to have intended. 该页面比上面的响应者所预期的要通用。 There is then an onwards pointer to this tutorial , which is good but does make a few assumptions that your development environment is more or less like the mongo developers'. 然后有一个指向本教程的指针,虽然很好,但是确实做了一些假设,即您的开发环境或多或少像mongo开发人员的一样。

It's not as smooth sailing as one might like, even on ubuntu 16.04. 即使在ubuntu 16.04上,航行也不如人们所愿。 Read it all with the prefix "Here be dragons" for now. 立即阅读所有带有前缀“ Here be dragons”的内容。

A couple notable issues: 几个值得注意的问题:

  • The tutorial points to a specific file to fetch via curl rather than pointing to the github repository and suggesting doing a clone. 本教程指向通过curl获取的特定文件,而不是指向github存储库并建议进行克隆。 This is a recipe for being a bit out of date. 这是过时的秘诀。 If I tell my infrastructure to fetch release 3.0.1, it will happily do that forever, rather than updating. 如果我告诉我的基础结构获取3.0.1版,它将很高兴永远做到这一点,而不是进行更新。 That said, it appears that compiling from git is fine. 也就是说,从git编译似乎很好。

  • A prerequisite is installing libmongoc. 前提条件是安装libmongoc。 It sure looks like installing from standard ubuntu packages is enough, since that's what the referenced page says. 看起来从标准ubuntu软件包安装就足够了,因为这就是所引用页面的内容。 But the mongocxx installer wants >=1.3.4. 但是mongocxx安装程序希望> = 1.3.4。 So installing from git is required. 因此需要从git安装。

  • It depends on libbson >= 1.3.4, which is later than the ubuntu 16.04 installed version. 它取决于libbson> = 1.3.4,此版本晚于ubuntu 16.04安装的版本。 So installing that, too, from git is required. 因此,也需要从git安装它。

  • Note that none of the git packages specify which branch or tag to request in order to get a production build. 请注意,所有git软件包都没有指定要获取生产版本的请求分支或标记。 Looking at all the tags on master and picking the numerically largest with no "rc" in the name seems to work. 查看master上的所有标签,并选择名称中没有“ rc”的数字最大标签。 A tag called "release" or "current" would be oh-so-kind. 名为“ release”或“ current”的标签会很普通。

  • The build (typing make ) tries to do a make install of the subpackage EP_mnmlstc_core, and this fails. 构建(键入make )尝试对子软件包EP_mnmlstc_core进行make安装,但失败。 So the entire build apparently has to run as root. 因此,整个构建显然必须以root用户身份运行。

  • At first pkg-config didn't work for me on mongocxx. 起初,pkg-config在mongocxx上对我不起作用。 Then it did. 然后它做到了。 I assume I made some subtle typo that I can't see looking back, but I still don't see it. 我想我做了一些微妙的错别字,我看不到回头,但我仍然看不到。 Alternatively, something happened since that got it working. 另外,发生了一些事情,因为它起作用了。

My compile line then is this: 我的编译行是这样的:

g++ --std=c++11 c++-hello-world-v3.cc -o hw   \
    $(pkg-config --cflags --libs libmongocxx) \
    -Xlinker -rpath /usr/local/lib

I would really like to file a documentation issue with all of this on mongo's github repo . 我真的很想在mongo的github repo上提交所有这些文档问题。 Unfortunately, they have disabled the issue tracker, instead point me to their jira instance, and there I appear not to have the right to create issues. 不幸的是,他们禁用了问题跟踪器,而是将我指向他们的jira实例,并且那里似乎没有创建问题的权利。 (Sometimes I miss what's in front of my nose, though.) [Update: David Golden kindly entered the bug info and noted how I might have as well.] (不过,有时我想念的是眼前的表情。)[更新:David Golden亲切地输入了错误信息,并指出了我可能也有这种感觉。]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM