[CXX-888] Quick function / Bson Multiadd KVP in BSON Created: 07/Apr/16  Updated: 11/Sep/19  Resolved: 14/Sep/16

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: 3.0.1
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Armin Ball [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hey there!
there is a JSON file in a BSON Object looking like the following.
I'm going to add in the marked areas the same attribut. I'm having problems in my loops to get the number of elements from a array. so I can't navigate in it. Only possible way I see is to iterate through every single element of the array and check if the returned value is 0x00 or valid.

Is there a faster way to do this?

{
    "_id" : ObjectId("5705918cb6a7d12aea0525f1"),
//add: "status" : 0
    "targets" : {
        "fast" : [ 
            {
                "size" : "poster",
                "format" : "jpg",
                "count" : 5
//add: "status" : 0
            }, 
            {
                "size" : "thumb",
                "format" : "jpg"
//add: "status" : 0
            }
        ],
        "slow" : [ 
            {
                "size" : "sd",
                "format" : "mp4"
//add: "status" : 0
            }, 
            {
                "size" : "sd",
                "format" : "webm"
//add: "status" : 0
            }
        ]
}}  

thx!
Armin



 Comments   
Comment by Armin Ball [X] [ 12/Apr/16 ]

Thank you for your time.

Comment by Matt Cotter [ 12/Apr/16 ]

Hi Weltenbummler,

I think this question was recently answered on the mongodb-user list. Please view the thread here: https://groups.google.com/forum/#!topic/mongodb-user/D7C5I4y-obY

To paraphrase Jason's response, if you want to add new keys in the middle of the existing BSON object, you'll have to create a new builder. You can iterate through your current document, copy the keys and values over, and add the new fields you want when you get to the right spot.

If that doesn't answer your question, please follow up on that same thread.

Thanks!
-Matt

Comment by Armin Ball [X] [ 09/Apr/16 ]

Thx,
didn't know that this google group exist.

Comment by Andrew Morrow (Inactive) [ 07/Apr/16 ]

Hi Weltenbummler - This kind of question is really better suited for the mongodb-user group:

https://groups.google.com/forum/#!forum/mongodb-user

Alternatively, if you like StackOverflow: http://stackoverflow.com/questions/tagged/mongo-cxx

We will work on this issue in this ticket, but in the future, please use one of those channels for questions. If we find a bug or improvement as a result of that discussion then we can open a ticket here.

Generated at Wed Feb 07 22:00:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.