[CSHARP-1588] incorrect json generation on ToJson Created: 02/Mar/16  Updated: 06/Apr/23  Resolved: 02/Mar/16

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.2.3
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Alexander Zel Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

.net 4.5.1



 Description   

Builders<BsonDocument>.Filter.In("Folders", new string[]

{ "URN:IVIS:100266:FLD-0000220" }

).ToJson()

Returns

"

{ \"_t\" : \"SingleItemAsArrayOperatorFilterDefinition`2\" }

"

But should be like this

"{Folders : { \"$in\" : ['URN:IVIS:100266:FLD-0000220']}}"



 Comments   
Comment by Alexander Zel [ 02/Mar/16 ]

Ok...
Thank You

Comment by Craig Wilson [ 02/Mar/16 ]

Hi Alexander,

This isn't a good way to get Json out of this type. There is a Render method on the returned value you can call with the correct arguments that will get you a BsonDocument. From there, you can call .ToString() on the BsonDocument.

var json = Builders<BsonDocument>.Filter.In("Folders", new string[]{ "URN:IVIS:100266:FLD-0000220" }).Render(BsonDocumentSerializer.Instance, BsonSerializer.SerializerRegistry).ToString()

Craig

Generated at Wed Feb 07 21:40:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.