简体   繁体   English

mgo API-mgo,mgo / bson,mgo / txn之间的差异

[英]mgo API - difference between mgo, mgo/bson, mgo/txn

I recently started learning Go and really like it so far. 我最近开始学习Go,到目前为止我真的很喜欢。 I would like to learn how to make a REST API with the mgo Mongo driver. 我想学习如何使用mgo Mongo驱动程序制作REST API。

At the website, there are three APIs: mgo , mgo/bson , mgo/txn . 在网站上,有三个API: mgomgo/bsonmgo/txn What do they mean? 他们的意思是什么?

Darshan is right: there are good references for those details at the project website . 达山(Darshan)是对的:在项目网站上有关于这些细节的很好的参考。 Specifically, you can find links to the package APIs of mgo , mgo/bson , and mgo/txn 具体来说,您可以找到指向mgomgo / bsonmgo / txn的软件包API的链接。

Just providing a quick overview of each of the packages, since this seems missing from the web page (I should fix that): 只是提供每个软件包的快速概述,因为似乎网页中没有(我应该解决):

labix.org/v2/mgo labix.org/v2/mgo

This is the MongoDB driver itself. 这是MongoDB驱动程序本身。 If you want to talk to a MongoDB database, this is the package to start with. 如果您想与MongoDB数据库对话,那么这是开始的软件包。 Have a look at the mgo.Dial function, and the example in the project website . 看一下mgo.Dial函数,以及项目网站中的示例。

labix.org/v2/mgo/bson labix.org/v2/mgo/bson

This package implements the marshaling and unmarshaling of BSON documents, following the BSON specification . 该软件包按照BSON规范实现BSON文档的封送处理。 It doesn't depend on any of the other two packages, and may be used by itself when one wants to simply serialize/deserialize documents in that format for whatever reason. 它不依赖于其他两个软件包中的任何一个,并且当出于某种原因想要简单地序列化/反序列化该格式的文档时,可以单独使用它。

The mgo package uses it to implement all marshaling and unmarshaling functionality, so the details you find in the documentation of the mgo/bson package in terms of field tags, etc, are all valid when working with the mgo package as well. mgo软件包使用它来实现所有封送处理和解封送功能,因此,在mgo/bson软件包的文档中以字段标签等为单位的详细信息在使用mgo软件包时同样有效。

labix.org/v2/mgo/txn labix.org/v2/mgo/txn

This package implements the mgo-specific multi-document transaction support for MongoDB . 该软件包为MongoDB实现了mgo特定的多文档事务支持 It implements its functionality on top of the mgo package, and neither of the other two packages depends on it. 它在mgo软件包之上实现其功能,而其他两个软件包都不依赖它。 If you're just getting started with your MongoDB use, you most probably don't need this package. 如果您只是开始使用MongoDB,则很可能不需要此软件包。

They aren't three separate APIs; 它们不是三个独立的API。 it's one API that's modularized. 这是一种模块化的API。 mgo is the core package. mgo是核心软件包。 mgo/bson is the BSON implementation. mgo/bson是BSON实现。 mgo/txn supports multi-document transactions. mgo/txn支持多文档交易。

You'd start by just using mgo and add either of the subpackages if you need the features they provide. 您只需要使用mgo ,如果需要它们提供的功能,请添加其中一个子包。 There's example code at the mgo homepage that demonstrates usage. mgo主页上有示例代码演示用法。

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

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