mongodb c api无插入无错误

mongodb c api无插入无错误,c,api,mongodb,g-wan,C,Api,Mongodb,G Wan,我正在尝试连接到mongodb并插入GET参数,使用G-WAN和mongodb的C驱动程序,我成功地连接到mongodb,但没有成功插入任何数据。 我正在使用代码 mongo_write_concern_init(write_concern); write_concern->w = 0; mongo_write_concern_finish(write_concern); bson b[1]; bson_init( b ); bson_append_new_oid( b, "_id" );

我正在尝试连接到mongodb并插入GET参数,使用G-WAN和mongodb的C驱动程序,我成功地连接到mongodb,但没有成功插入任何数据。 我正在使用代码

mongo_write_concern_init(write_concern);
write_concern->w = 0;
mongo_write_concern_finish(write_concern);
bson b[1];
bson_init( b );
bson_append_new_oid( b, "_id" );
bson_append_string( b, "param1", param1);
bson_append_string( b, "param2", param2);

status = mongo_insert( conn, "mydb.mycol", b , write_concern);
bson_finish( b );
bson_destroy( b );
mongo_write_concern_destroy(write_concern);
连接成功,我可以通过mongod.log文件查看

[conn36] run command admin.$cmd { ismaster: 1 }
[conn36] command admin.$cmd command: { ismaster: 1 } ntoreturn:1 reslen:71 0ms
[conn36] end connection 127.0.0.1:50086
但除此之外,我无法获取任何错误消息或错误日志,当我调用上次错误时,也无法在mongodb shell上获取任何错误消息或错误日志

> db.getLastError()
null
返回空值
欢迎您了解发生这种情况的原因或提供任何解决方案建议,谢谢您

必须在mongo_insert()之前拨打此电话:

否则,此处有一个未完成的BSON对象:

status = mongo_insert( conn, "mydb.mycol", b , write_concern);
所以代码应该是

bson b[1];

/// Init
bson_init( b );
bson_append_new_oid( b, "_id" );
bson_append_string( b, "param1", param1);
bson_append_string( b, "param2", param2);

// Make this complete
bson_finish( b );

/// Insert
status = mongo_insert( conn, "mydb.mycol", b , write_concern);

/// Destroy the BSON obj
bson_destroy( b );

谢谢,我还发现mongodb的write concern函数的linux c驱动程序的最新git版本在我的代码中总是返回错误,所以我使用了mongodb c驱动程序的v0.5.2,现在我可以插入任何我想要的内容。还有一点,我正在尝试构建一个统计服务器,所以我选择了mongodb和c,但是大约55k的请求,mongodb开始没有响应,大约每秒10k的请求,这只是早期的生产测试,所以我想我必须切换数据库服务器或优化mongodb以满足我的需要,欢迎任何建议,谢谢
bson b[1];

/// Init
bson_init( b );
bson_append_new_oid( b, "_id" );
bson_append_string( b, "param1", param1);
bson_append_string( b, "param2", param2);

// Make this complete
bson_finish( b );

/// Insert
status = mongo_insert( conn, "mydb.mycol", b , write_concern);

/// Destroy the BSON obj
bson_destroy( b );