设为首页 收藏本站
查看: 1406|回复: 0

[经验分享] Allan 译 The Little MongoDB Book (Getting Started)

[复制链接]

尚未签到

发表于 2015-7-7 08:08:36 | 显示全部楼层 |阅读模式
  译文:
  这本书将专注于MongoDB的功能性。因此,我们将依赖MongoDB的shell。作为一个管理工具,shell的学习是非常有用的,
你的代码将使用MongoDB的驱动程序。
有关DongoDB你第一个需要了解的是:驱动程序。MongoDB有各种不同语言的官方驱动。你可以把这些驱动理解为你可能
已经非常了解的其它各种数据库的驱动器。在这些驱动器上,开发社区已经建立了更多的语言/框架库。例如,NoRM是一个
实现LINQ的C#库,MongoMaper是一个ActiveRecord-friendly 的ruby库。你可以选择直接使用MongoDB核心驱动或者一些更高
级别的库。我指出这些的原因是因为很多新接触MongoDB的人对于为什么同时存在官方驱动和社区驱动感到很混乱-前者
更多的关注于MongoDB核心的通信/连通性,后者更多的关注于语言和框架的特定实现。
读到这,我鼓励你们把我的示例复制到你自已的MongoDB上,这样可以使你发现问题。运行MongoDB非常的简单,我们用
几分钟把事情解决。
1 根据你的系统去官网下载适当的二进制文件,你可以选择32位或64位。
2 解压归档文件并进入bin子目录。不要直接运行,mongodb是一个服务器进程而mongo是一个客户端的shell-我们将在这两个可
   执行花费大量的时间。
3 在bin目录下建立一个mongodb.config文件
4 在mongodb.config文件下添加一行dbpath=PATH_TO_WHERE_YOU_WANT_TO_STORE_YOUR_DATABASE_,例如,在windows
   下你可能是dbpath=c:\mongodb\data, 在linux下你可能是dbpath=/etc/mongodb/data。
5 确保你指定的目录dbpath存在
6 使用--config /path/to/your/mongodb.config参数启动mongod
Windows用户示例:如果你把下载文件解压到c:\mongodb\ 并且你创建了c:\mongodb\data\ 然后在c:\mongodb\bin\mongodb.config
你指定了dbpath=c:\mongodb\data\,你就可以使用以下命令启动mongod:c:\mongodb\bin\mongod --config c:\mongodb.config。
希望你的MongoDB运行起来。如果你收到错误信息,仔细的阅读输入信息-服务器可非常不错的解释发生了什么错误。
现在你可以运行mongo(没有d)为你的服务器连接一个shell。尝试输入db.version()来确保所有的事情运行正常。希望你看到你安装的版本号。
  
  原文:
  Most of this book will focus on core MongoDB functionality. We'll therefore rely on the MongoDB shell. While the shell is useful to learn as well as being a useful administrative tool, your code will use a MongoDB driver.
  This does bring up the first thing you should know about MongoDB: its drivers. MongoDB has a number of official drivers for various languages. These drivers can be thought of as the various database drivers you are probably already familiar with. On top of these drivers, the development community has built more language/framework-specific libraries. For example, NoRM is a C# library which implements LINQ, and MongoMapper is a Ruby library which is ActiveRecord-friendly. Whether you choose to program directly against the core MongoDB drivers or some higher-level library is up to you. I point this out only because many people new to MongoDB are confused as to why there are both official drivers and community libraries - the former generally focuses on core communication/connectivity with MongoDB and the latter with more language and framework specific implementations.
  
As you read through this, I encourage you to play with MongoDB to replicate what I demon-strate as well as to explore questions that might come up on your own. It's easy to get up and running with MongoDB, so let's take a few minutes now to set things up.
  
1. Head over to the official download page and grab the binaries from the first row (the recommended stable version) for your operating system of choice. For development purposes, you can pick either 32-bit or 64-bit.
2. Extract the archive (wherever you want) and navigate to the bin subfolder. Don't execute anything just yet, but know that mongod is the server process and mongo is the client shell- these are the two executables we'll be spending most of our time with.
3. Create a new text file in the bin subfolder named mongodb.config
4. Add a single line to your mongodb.config: dbpath=PATH_TO_WHERE_YOU_WANT_TO_STORE_YOUR_DATABASE_F
   . For example, on Windows you might do dbpath=c:\mongodb\data and on Linux you might do dbpath=/etc/mongo/data.
5. Make sure the dbpath you specified exists
6. Launch mongod with the --config /path/to/your/mongodb.config parameter.
  
As an example for Windows users, if you extracted the downloaded file to c:\mongodb\ and you created c:\mongodb\data\ then within c:\mongodb\bin\mongodb.config you would specify dbpath=c:\mongodb\data\. You could then launch mongod from a command prompt via c:\mongodb\bin\mongod --config c:\mongodb\bin\mongodb.config.
  
Feel free to add the bin folder to your path to make all of this less verbose. MacOSX and Linux users can follow almost identical directions. The only thing you should have to change are the paths.
  
Hopefully you now have MonogDB up and running. If you get an error, read the output carefully- the server is quite good at explaining what's wrong.
You can now launch mongo (without the d) which will connect a shell to your running server. Try entering db.version() to make sure everything's working as it should. Hopefully you'll see the version number you installed.
  
  
  作者努力翻译,希望转载者注明文章出处及作者。谢谢

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-83885-1-1.html 上篇帖子: MongoDB学习笔记(五)--复制集 && sharding分片 下篇帖子: MongoDB进行MapReduce的数据类型
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表