[JAVA-2000] Add toString() methods to Bson instances returned from static builder methods Created: 06/Oct/15  Updated: 31/Jan/18  Resolved: 15/Jun/16

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: 3.1.0
Fix Version/s: 3.3.0

Type: New Feature Priority: Major - P3
Reporter: Jeff Schnitzer Assignee: Jeffrey Yemin
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-2092 Add equals() and toString() to Updates Closed
Related
related to JAVA-2762 Add toString() methods to model class Closed

 Description   

The objects returned by the Filters.* and Aggregates.* and other static builder methods are really hard to debug since they log opaquely. Please add toString() methods

Builder classes to include:

  • Filters
  • Updates
  • Projections
  • Sorts
  • Aggregates
  • Accumulators


 Comments   
Comment by Githook User [ 15/Jun/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2000: Add toString methods to all Bson implementations returned from static methods of builder classes

Includes Filters, Projections, Updates, Sorts, Aggregates, and Accumulators
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/d1af237cc1776394caa8f0baa0707bc4314a6ee6

Comment by Jeffrey Yemin [ 06/Oct/15 ]

Sure, that's true. I'll leave this open then, and you can use my suggestion as a workaround until it's fixed.

Comment by Jeff Schnitzer [ 06/Oct/15 ]

To turn a Bson into JSON, yes - but it doesn't need to be JSON. Simply having all relevant implementations stringify their member data in an arbitrary form is incredibly useful while logging and debugging. toString()'s contract does not require any particular format.

Comment by Jeffrey Yemin [ 06/Oct/15 ]

In order to properly turn a Bson instance into a JSON string, a CodecRegistry is needed. That's why there is currently no toString() method available.

You can call toString on:

  toBsonDocument(collection.getDocumentClass(), collection.getCodecRegistry())

and it will be guaranteed to work.

Generated at Thu Feb 08 08:56:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.