孤独雪鹰 发表于 2015-7-8 08:24:41

mongodb(基础用法)

驱动和客户端库
  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


[*]论坛
[*]日志
[*]下载
[*]驱动
[*]活动
[*]翻译





窗体顶端

























窗体底端


[*]编辑




[*]GitHub




[*]报告问题



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.





SQL



mongo Shell



C++ Driver







INSERT INTO USERS
VALUES( 1, 1)



db.users.insert( { a: 1, b: 1 } )



// GENOID is optional. if not done by client,
// server will add an _id

c.insert("mydb.users",
BSON(GENOID
页: [1]
查看完整版本: mongodb(基础用法)