I have to read a document from mongodb such that the field on which I want to apply the search is an array. Example:
Say db contains:
[
{
_id: ObjectId("6476d33e8258c0b6563324b4"),
tag: ['a1', 'a2' , 'a3'],
age : 21,
val: [ '101', '102' ]
},
{
_id: ObjectId("6476d33e8258c0b6563324b5"),
tag: ['b1', 'b2' , 'b3'],
age : 21,
val: [ '103', '104' ]
}
Now I have to fetch all documents from the db such that 'tag' is say 'a2'. Further, I have to return the 'val' field (which is an array) corresponding to all the fetched documents of previous query result.
The only language I can use in my project is C. Can someone kindly help me in this? I have done something similar in past in python. But I have no idea how to handle such query for mongodb in C
I tried doing the follwing using MongoDB C Driver (libmongoc-1.0) :
BSON_APPEND_UTF8 (query, "tag", "a2");
cursor = mongoc_collection_find_with_opts (collection, query, NULL, NULL);
But it did not work and returned an empty result for me.