我向mongo存储了一个文件:
json::Value conditions(json::objectValue);
conditions["agentId"] = (json::Int64)111;
conditions["fileId"] = (json::Int64)222;
bson_t *bs = bson_new();
_jsonToBson(conditions, bs);
opt.metadata = ( const bson_t *)bs;
opt.content_type = "333";
file = mongoc_gridfs_create_file_from_stream (gridfs, stream, &opt);
bson_destroy(bs);
if(file)
{
mongoc_gridfs_file_save(file);
mongoc_gridfs_file_destroy(file);
}
但是通过mongoc_gridfs_find_one查找的时候:
json::Value conditions(json::objectValue);
conditions["contentType"] = "333"; //或者通过"_id"
bson_t *bs = bson_new();
_jsonToBson(conditions, bs);
file = mongoc_gridfs_find_one(gridfs,(const bson_t *)bs,&error);
bson_destroy(bs);
可以查找到文件对象!
conditions["metadata"]["fileId"] = (json::Int64)222; //通过metadata 无法查到文件
有大神知道怎么回事吗?