Я пытаюсь найти документ по имени поля, находящемуся внутри объекта. у меня есть этот 1 документ внутри имен коллекции «TestCollection»Драйвер MongoDB C mongoc_collection_find() не может найти документ по полю
{
"_id" : ObjectId("56c2f0f3892b312e740041a1"),
"Obj" : {
"Type" : 0,
"Num" : NumberLong(1111111111111)
}
}
На основе этого урока: http://api.mongodb.org/c/current/tutorial.html#find
И этот API документ о «найти» я узнать, что мне нужно использовать точечную нотацию для поиска по Obj.Num Я пытаюсь найти этот документ так:
mongoc_collection_t *collection = NULL;
mongoc_cursor_t *cursor = NULL;
const bson_t *doc = NULL;
char *str = NULL;
bson_t * query = bson_new();
std::string str;
bool b = BSON_APPEND_INT64(query,"TestCollection.Num",1111111111111);
// b is true
collection = mongoc_client_get_collection(m_mogoClient,"CollectionDB","Obj.Num");
cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
while (mongoc_cursor_next (cursor, &doc)) {
//it is never gets here to print the document
str = bson_as_json (doc, NULL);
printf ("%s\n", str);
bson_free (str);
}
bson_destroy (query);
mongoc_cursor_destroy (cursor);
mongoc_collection_destroy (collection);
для проверки запроса я запустить его в MongoDB оболочки и я действительно получил обратно результат документа, как вы видите:
> use CollectionDB
switched to db CollectionDB
> db
Collection
> db.TestCollection.find(
... {
... "Obj.Num":1111111111111
... }
...)
{ "_id" : ObjectId("56c2f0f3892b312e740041a1"), "Obj" : { "Type" : 0, "Num" : NumberLong("1111111111111") } }
>
Что не так в коде c, почему он не возвращает мне результат? благодаря