驱动和客户端库
https://mongodb-documentation.readthedocs.org/en/latest/ecosystem/drivers.html#id2
https://mongodb-documentation.readthedocs.org/en/latest/ecosystem/drivers/cpp-to-sql-to-mongo-shell.html
窗体顶端
窗体底端
SQL tomongoShell to C++
MongoDB queries are expressed as JSON (BSON) objects. This quick reference chart shows examples as SQL, mongo shell syntax, and MongoDB C++ driver syntax.
A query expression in MongoDB (and other things, such as an index key pattern) is represented as BSON. In C++ you can use BSONObjBuilder (aka bson::bob) to build BSON objects, or the BSON() macro. The examples below assume a connection c already established:
using namespace bson;
DBClientConnection c;
c.connect("somehost");
Several of the C++ driver methods throw mongo::DBException, so you will want a try/catch statement as some level in your program. Also be sure to call c.getLastError() after writes to check the error code.
[table]
[tr]
[td]
SQL
[/td]
[td]
mongo Shell
[/td]
[td]
C++ Driver
[/td]
[/tr]
[tr]
[td]
INSERT INTO USERS
VALUES( 1, 1)
[/td]
[td]
db.users.insert( { a: 1, b: 1 } )
[/td]
[td]
// GENOID is optional. if not done by client,
// server will add an _id
c.insert("mydb.users",
BSON(GENOID |