Search code examples
c++regexmongodbbson

How to write Regular Expression for BSON Object in c++?


I am having BSON object like this,

{ "0" : "Kollywood", "1" : "Tollywood" }

I am going to use this bson object $in query in mongo db to get all matched tags without case sensitive. but i am getting exactly matched result alone.

{

    "result": [
        {
            "_id": 110, 
            "tags": [
                {
                    "id": "5524cdfffe13b4934bbd6cab", 
                    "name": "Kollywood"
                }
            ]
        }
    ], 
    "ok": 1
}

My requirement is,(All matched tags without case sensitive)

{

        "result": [
            {
                "_id": 110, 
                "tags": [
                    {
                        "id": "5524cdfffe13b4934bbd6cab", 
                        "name": "Kollywood"
                    },
                    {
                        "id": "5524cdfffe13b4934bbd6cab", 
                        "name": "KollyWOOD"
                    }
                ]
            }
        ], 
        "ok": 1
    }

How can i do this in c++?


Solution

  • { "0" : "Kollywood", "1" : "Tollywood" } this is the query object, i have to convert this as a following manner

                {
                    "$or": [
                        {
                            "tags.name": {
                                "$regex": "^kolly wood", 
                                "$options": "xi"
                            }
                        }, 
                        {
                            "tags.name": {
                                "$regex": "^tolly wood", 
                                "$options": "xi"
                            }
                        }
                    ]
                }