How to parse bsoncxx::to_json?

121 views
Skip to first unread message

Yashashree Jadhav

unread,
Jul 26, 2018, 10:39:32 PM7/26/18
to BSON
Hello,


I want to parse  data from bsoncxx::to_json(doc). Is any one have experience with this.

 mongocxx::cursor ncursor = collectionpddl.find({});
 
    for(auto doc : ncursor)
    {  
    
          if( bsoncxx::to_json(doc) == "_id")
          {
                 std::cout << "parse" << "\n";
                
          }
              
    }

Kindly help me out.

Thank you and Regards.

Dwight Merriman

unread,
Jul 28, 2018, 12:36:07 PM7/28/18
to bs...@googlegroups.com
not sure what you are trying to do.  after to_json you will get a string something like 

  { "_id" : ... , "field2" : ... , ... }

generally you should only need to convert the bson to json if you are going to output to something outside your application, such as a .json file or perhaps another process via REST.

for debugging purposes start with something in the loop such as 

string s = to_json(doc);
cout << s << endl;


--
You received this message because you are subscribed to the Google Groups "BSON" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bson+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Deploy, operate and scale MongoDB in the cloud with just a few clicks
https://www.mongodb.com/cloud/atlas

Andrew Morrow

unread,
Jul 29, 2018, 10:03:05 AM7/29/18
to bs...@googlegroups.com

Hi -

Lets continue the existing discussion of this topic that is happening on mongodb-dev (https://groups.google.com/d/msgid/mongodb-dev/a9ba12fc-6129-4580-9ca7-bc50d8e9c7fe%40googlegroups.com?utm_medium=email&utm_source=footer) rather than starting a new thread here.

Thanks,
Andrew




On Sat, Jul 28, 2018 at 12:36 PM 'Dwight Merriman' via BSON <bs...@googlegroups.com> wrote:
not sure what you are trying to do.  after to_json you will get a string something like 

  { "_id" : ... , "field2" : ... , ... }

generally you should only need to convert the bson to json if you are going to output to something outside your application, such as a .json file or perhaps another process via REST.

for debugging purposes start with something in the loop such as 

string s = to_json(doc);
cout << s << endl;

On Tue, Jul 24, 2018 at 6:13 AM, Yashashree Jadhav <yashashre...@gmail.com> wrote:
Hello,


I want to parse  data from bsoncxx::to_json(doc). Is any one have experience with this.

 mongocxx::cursor ncursor = collectionpddl.find({});
 
    for(auto doc : ncursor)
    {  
    
          if( bsoncxx::to_json(doc) == "_id")
          {
                 std::cout << "parse" << "\n";
                
          }
              
    }

Kindly help me out.

Thank you and Regards.

--
You received this message because you are subscribed to the Google Groups "BSON" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bson+uns...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Deploy, operate and scale MongoDB in the cloud with just a few clicks
https://www.mongodb.com/cloud/atlas

--
You received this message because you are subscribed to the Google Groups "BSON" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bson+uns...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages