I need help decoding Bson. I am making a WebRequest and getting
encoded Bson blob which I need to decode in C#. IN java you would do
something like this
but I need to do similar in C#. Could somebody help me do this in C#?
What would be BSONDecoder equivalant in C#? I have the Mongo
Driver,BSON DLL so i just need to find out the right set of calls to
decode it.
On Thu, May 24, 2012 at 6:38 PM, sLaVeN <slug...@gmail.com> wrote:
> Hi,
> I need help decoding Bson. I am making a WebRequest and getting
> encoded Bson blob which I need to decode in C#. IN java you would do
> something like this
> but I need to do similar in C#. Could somebody help me do this in C#?
> What would be BSONDecoder equivalant in C#? I have the Mongo
> Driver,BSON DLL so i just need to find out the right set of calls to
> decode it.
On Thu, May 24, 2012 at 6:43 PM, Robert Stam <rob...@10gen.com> wrote:
> Write whatever code you need to get the BSON data as a byte array, and
> then you can decode it using:
> On Thu, May 24, 2012 at 6:38 PM, sLaVeN <slug...@gmail.com> wrote:
>> Hi,
>> I need help decoding Bson. I am making a WebRequest and getting
>> encoded Bson blob which I need to decode in C#. IN java you would do
>> something like this
>> but I need to do similar in C#. Could somebody help me do this in C#?
>> What would be BSONDecoder equivalant in C#? I have the Mongo
>> Driver,BSON DLL so i just need to find out the right set of calls to
>> decode it.
Thanks Robert for the quick reply. I tried that but I am getting an
exception.
string bson = File.ReadAllText(@"C:\Users\myuser\Desktop\bson.txt");
byte[] bytesarr = Encoding.UTF8.GetBytes(bson); // Tried different
Encoding here but that didn't seem to matter.
BsonDocument document =
MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(bytesar r);
Steps:
1) Convert bsonresponse to bytes array
2) Call the Deserializer you have provided
3) Execute and i get following exception
Unhandled Exception: System.IO.EndOfStreamException: Attempted to read
past the
end of the stream.
at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream, Int32 count)
at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream)
at MongoDB.Bson.IO.BsonReader.Create(Stream stream,
BsonBinaryReaderSettings
settings)
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream
stream, Type
nominalType)
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Byte[]
bytes, Type n
ominalType)
at
MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType]
(Byte[]
bytes)
at Test.Program.Main(String[] args) in C:\project
\XPathFormatingTools\Test\Te
st\Program.cs:line 54
Thanks Alot!
On May 24, 3:49 pm, Robert Stam <rob...@10gen.com> wrote:
> You can also deserialize BSON data directly from a binary stream, like this:
> Stream stream;
> var document = BsonSerializer.Deserialize<BsonDocument>(stream);
> On Thu, May 24, 2012 at 6:43 PM, Robert Stam <rob...@10gen.com> wrote:
> > Write whatever code you need to get the BSON data as a byte array, and
> > then you can decode it using:
> > On Thu, May 24, 2012 at 6:38 PM, sLaVeN <slug...@gmail.com> wrote:
> >> Hi,
> >> I need help decoding Bson. I am making a WebRequest and getting
> >> encoded Bson blob which I need to decode in C#. IN java you would do
> >> something like this
> >> but I need to do similar in C#. Could somebody help me do this in C#?
> >> What would be BSONDecoder equivalant in C#? I have the Mongo
> >> Driver,BSON DLL so i just need to find out the right set of calls to
> >> decode it.
> Steps:
> 1) Convert bsonresponse to bytes array
> 2) Call the Deserializer you have provided
> 3) Execute and i get following exception
> Unhandled Exception: System.IO.EndOfStreamException: Attempted to read
> past the
> end of the stream.
> at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream, Int32 count)
> at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream)
> at MongoDB.Bson.IO.BsonReader.Create(Stream stream,
> BsonBinaryReaderSettings
> settings)
> at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream
> stream, Type
> nominalType)
> at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Byte[]
> bytes, Type n
> ominalType)
> at
> MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType]
> (Byte[]
> bytes)
> at Test.Program.Main(String[] args) in C:\project
> \XPathFormatingTools\Test\Te
> st\Program.cs:line 54
> Thanks Alot!
> On May 24, 3:49 pm, Robert Stam <rob...@10gen.com> wrote:
> > You can also deserialize BSON data directly from a binary stream, like
> this:
> > Stream stream;
> > var document = BsonSerializer.Deserialize<BsonDocument>(stream);
> > On Thu, May 24, 2012 at 6:43 PM, Robert Stam <rob...@10gen.com> wrote:
> > > Write whatever code you need to get the BSON data as a byte array, and
> > > then you can decode it using:
> > > On Thu, May 24, 2012 at 6:38 PM, sLaVeN <slug...@gmail.com> wrote:
> > >> Hi,
> > >> I need help decoding Bson. I am making a WebRequest and getting
> > >> encoded Bson blob which I need to decode in C#. IN java you would do
> > >> something like this
> > >> but I need to do similar in C#. Could somebody help me do this in C#?
> > >> What would be BSONDecoder equivalant in C#? I have the Mongo
> > >> Driver,BSON DLL so i just need to find out the right set of calls to
> > >> decode it.
yes, there could have been an issue there because I was trying to
convert the stream to string as well as bytes array which was giving
me those issues. However, I tried now to pass in the stream directly
to the Deserializer and it looks like its trying to do something but
complains about Duplicate element. There is no duplicate element. We
have WebApp where we can make these calls and Json that Im getting
back is fine, no duplicates but when i try to do it from my C# code, i
get the following error. Could there be a bug in the Driver? Thanks
Unhandled Exception: System.InvalidOperationException: Duplicate
element name 'm
_fleg'.
at MongoDB.Bson.BsonDocument.Add(BsonElement element)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
BsonElement& elem
ent)
at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
Type nominalT
ype, IBsonSerializationOptions options)
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader
bsonReade
r, Type nominalType, IBsonSerializationOptions options)
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream
stream, Type
nominalType)
at
MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType]
(Stream
stream)
at Test.Program.HttpRequest() in C:\project\XPathFormatingTools\Test
\Test\Pro
gram.cs:line 86
at Test.Program.Main(String[] args) in C:\project
\XPathFormatingTools\Test\Te
st\Program.cs:line 61
Press any key to continue . . .
On May 24, 7:29 pm, Robert Stam <rob...@10gen.com> wrote:
> BSON is a binary encoding. If your file is not a binary file you won't be
> able to decode it as BSON.
> If your file is a text file containing JSON you will want to parse it a
> different way:
> string json; // load this from your file
> BsonDocument document = BsonSerializer.Deserialize<BsonDocument>(json);
> On Thu, May 24, 2012 at 7:57 PM, sLaVeN <slug...@gmail.com> wrote:
> > Thanks Robert for the quick reply. I tried that but I am getting an
> > exception.
> > string bson = File.ReadAllText(@"C:\Users\myuser\Desktop\bson.txt");
> > byte[] bytesarr = Encoding.UTF8.GetBytes(bson); // Tried different
> > Encoding here but that didn't seem to matter.
> > BsonDocument document =
> > > On Thu, May 24, 2012 at 6:43 PM, Robert Stam <rob...@10gen.com> wrote:
> > > > Write whatever code you need to get the BSON data as a byte array, and
> > > > then you can decode it using:
> > > > On Thu, May 24, 2012 at 6:38 PM, sLaVeN <slug...@gmail.com> wrote:
> > > >> Hi,
> > > >> I need help decoding Bson. I am making a WebRequest and getting
> > > >> encoded Bson blob which I need to decode in C#. IN java you would do
> > > >> something like this
> > > >> but I need to do similar in C#. Could somebody help me do this in C#?
> > > >> What would be BSONDecoder equivalant in C#? I have the Mongo
> > > >> Driver,BSON DLL so i just need to find out the right set of calls to
> > > >> decode it.
Is the stream you are passing in encoded in BSON or is it a JSON string encoded as binary? As in, does the stream match the bson spec here: http://bsonspec.org/#/specification?
On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> Hi Robert,
> yes, there could have been an issue there because I was trying to > convert the stream to string as well as bytes array which was giving > me those issues. However, I tried now to pass in the stream directly > to the Deserializer and it looks like its trying to do something but > complains about Duplicate element. There is no duplicate element. We > have WebApp where we can make these calls and Json that Im getting > back is fine, no duplicates but when i try to do it from my C# code, i > get the following error. Could there be a bug in the Driver? Thanks
> Unhandled Exception: System.InvalidOperationException: Duplicate > element name 'm > _fleg'. > at MongoDB.Bson.BsonDocument.Add(BsonElement element) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > BsonElement& elem > ent) > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > Type nominalT > ype, IBsonSerializationOptions options) > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader > bsonReade > r, Type nominalType, IBsonSerializationOptions options) > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream > stream, Type > nominalType) > at > MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType] > (Stream > stream) > at Test.Program.HttpRequest() in C:\project\XPathFormatingTools\Test > \Test\Pro > gram.cs:line 86 > at Test.Program.Main(String[] args) in C:\project > \XPathFormatingTools\Test\Te > st\Program.cs:line 61 > Press any key to continue . . .
> On May 24, 7:29 pm, Robert Stam <rob...@10gen.com> wrote: > > BSON is a binary encoding. If your file is not a binary file you won't > be > > able to decode it as BSON.
> > If your file is a text file containing JSON you will want to parse it a > > different way:
> > string json; // load this from your file > > BsonDocument document = BsonSerializer.Deserialize<BsonDocument>(json);
> > On Thu, May 24, 2012 at 7:57 PM, sLaVeN <slug...@gmail.com> wrote: > > > Thanks Robert for the quick reply. I tried that but I am getting an > > > exception.
> > > string bson = File.ReadAllText(@"C:\Users\myuser\Desktop\bson.txt"); > > > byte[] bytesarr = Encoding.UTF8.GetBytes(bson); // Tried different > > > Encoding here but that didn't seem to matter. > > > BsonDocument document =
> > > Steps: > > > 1) Convert bsonresponse to bytes array > > > 2) Call the Deserializer you have provided > > > 3) Execute and i get following exception
> > > Unhandled Exception: System.IO.EndOfStreamException: Attempted to read > > > past the > > > end of the stream. > > > at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream, Int32 count) > > > at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream) > > > at MongoDB.Bson.IO.BsonReader.Create(Stream stream, > > > BsonBinaryReaderSettings > > > settings) > > > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream > > > stream, Type > > > nominalType) > > > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Byte[] > > > bytes, Type n > > > ominalType) > > > at > > > MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType] > > > (Byte[] > > > bytes) > > > at Test.Program.Main(String[] args) in C:\project > > > \XPathFormatingTools\Test\Te > > > st\Program.cs:line 54
> > > Thanks Alot!
> > > On May 24, 3:49 pm, Robert Stam <rob...@10gen.com> wrote: > > > > You can also deserialize BSON data directly from a binary stream, > like > > > this:
> > > > On Thu, May 24, 2012 at 6:43 PM, Robert Stam <rob...@10gen.com> > wrote: > > > > > Write whatever code you need to get the BSON data as a byte array, > and > > > > > then you can decode it using:
> > > > > On Thu, May 24, 2012 at 6:38 PM, sLaVeN <slug...@gmail.com> > wrote:
> > > > >> Hi,
> > > > >> I need help decoding Bson. I am making a WebRequest and getting > > > > >> encoded Bson blob which I need to decode in C#. IN java you would > do > > > > >> something like this
Hmm, I am not sure how the server is returning it to me but I would
assume it would be BSON because we have some other apps that do
similar things and display it as JSON. However, I could go with an
assumption that it could be JSON encoded as binary. If thats the case,
how would I got about decoding the Json Binary to regular JSON?
Thanks
On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com> wrote:
> Is the stream you are passing in encoded in BSON or is it a JSON string
> encoded as binary? As in, does the stream match the bson spec here: http://bsonspec.org/#/specification?
> On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > Hi Robert,
> > yes, there could have been an issue there because I was trying to
> > convert the stream to string as well as bytes array which was giving
> > me those issues. However, I tried now to pass in the stream directly
> > to the Deserializer and it looks like its trying to do something but
> > complains about Duplicate element. There is no duplicate element. We
> > have WebApp where we can make these calls and Json that Im getting
> > back is fine, no duplicates but when i try to do it from my C# code, i
> > get the following error. Could there be a bug in the Driver? Thanks
> > Unhandled Exception: System.InvalidOperationException: Duplicate
> > element name 'm
> > _fleg'.
> > at MongoDB.Bson.BsonDocument.Add(BsonElement element)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
> > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> > BsonElement& elem
> > ent)
> > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> > Type nominalT
> > ype, IBsonSerializationOptions options)
> > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader
> > bsonReade
> > r, Type nominalType, IBsonSerializationOptions options)
> > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream
> > stream, Type
> > nominalType)
> > at
> > MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType]
> > (Stream
> > stream)
> > at Test.Program.HttpRequest() in C:\project\XPathFormatingTools\Test
> > \Test\Pro
> > gram.cs:line 86
> > at Test.Program.Main(String[] args) in C:\project
> > \XPathFormatingTools\Test\Te
> > st\Program.cs:line 61
> > Press any key to continue . . .
> > On May 24, 7:29 pm, Robert Stam <rob...@10gen.com> wrote:
> > > BSON is a binary encoding. If your file is not a binary file you won't
> > be
> > > able to decode it as BSON.
> > > If your file is a text file containing JSON you will want to parse it a
> > > different way:
> > > string json; // load this from your file
> > > BsonDocument document = BsonSerializer.Deserialize<BsonDocument>(json);
> > > On Thu, May 24, 2012 at 7:57 PM, sLaVeN <slug...@gmail.com> wrote:
> > > > Thanks Robert for the quick reply. I tried that but I am getting an
> > > > exception.
> > > > string bson = File.ReadAllText(@"C:\Users\myuser\Desktop\bson.txt");
> > > > byte[] bytesarr = Encoding.UTF8.GetBytes(bson); // Tried different
> > > > Encoding here but that didn't seem to matter.
> > > > BsonDocument document =
> > > > Steps:
> > > > 1) Convert bsonresponse to bytes array
> > > > 2) Call the Deserializer you have provided
> > > > 3) Execute and i get following exception
> > > > Unhandled Exception: System.IO.EndOfStreamException: Attempted to read
> > > > past the
> > > > end of the stream.
> > > > at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream, Int32 count)
> > > > at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream)
> > > > at MongoDB.Bson.IO.BsonReader.Create(Stream stream,
> > > > BsonBinaryReaderSettings
> > > > settings)
> > > > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream
> > > > stream, Type
> > > > nominalType)
> > > > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Byte[]
> > > > bytes, Type n
> > > > ominalType)
> > > > at
> > > > MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType]
> > > > (Byte[]
> > > > bytes)
> > > > at Test.Program.Main(String[] args) in C:\project
> > > > \XPathFormatingTools\Test\Te
> > > > st\Program.cs:line 54
> > > > Thanks Alot!
> > > > On May 24, 3:49 pm, Robert Stam <rob...@10gen.com> wrote:
> > > > > You can also deserialize BSON data directly from a binary stream,
> > like
> > > > this:
> > > > > On Thu, May 24, 2012 at 6:43 PM, Robert Stam <rob...@10gen.com>
> > wrote:
> > > > > > Write whatever code you need to get the BSON data as a byte array,
> > and
> > > > > > then you can decode it using:
Well, here's a test. Take the stream you are getting from the server, use Encoding.UTF8.GetString(byetArray) and save that to a file. if it is legible, then it is a json string. If not, we'll go from there.
On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> Hmm, I am not sure how the server is returning it to me but I would > assume it would be BSON because we have some other apps that do > similar things and display it as JSON. However, I could go with an > assumption that it could be JSON encoded as binary. If thats the case, > how would I got about decoding the Json Binary to regular JSON?
> Thanks
> On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com> wrote: > > Is the stream you are passing in encoded in BSON or is it a JSON string > > encoded as binary? As in, does the stream match the bson spec here:
> http://bsonspec.org/#/specification?
> > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > > Hi Robert,
> > > yes, there could have been an issue there because I was trying to > > > convert the stream to string as well as bytes array which was giving > > > me those issues. However, I tried now to pass in the stream directly > > > to the Deserializer and it looks like its trying to do something but > > > complains about Duplicate element. There is no duplicate element. We > > > have WebApp where we can make these calls and Json that Im getting > > > back is fine, no duplicates but when i try to do it from my C# code, i > > > get the following error. Could there be a bug in the Driver? Thanks
> > > Unhandled Exception: System.InvalidOperationException: Duplicate > > > element name 'm > > > _fleg'. > > > at MongoDB.Bson.BsonDocument.Add(BsonElement element) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader) > > > at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, > > > BsonElement& elem > > > ent) > > > at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, > > > Type nominalT > > > ype, IBsonSerializationOptions options) > > > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader > > > bsonReade > > > r, Type nominalType, IBsonSerializationOptions options) > > > at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream > > > stream, Type > > > nominalType) > > > at > > > MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType] > > > (Stream > > > stream) > > > at Test.Program.HttpRequest() in > C:\project\XPathFormatingTools\Test > > > \Test\Pro > > > gram.cs:line 86 > > > at Test.Program.Main(String[] args) in C:\project > > > \XPathFormatingTools\Test\Te > > > st\Program.cs:line 61 > > > Press any key to continue . . .
> > > On May 24, 7:29 pm, Robert Stam <rob...@10gen.com> wrote: > > > > BSON is a binary encoding. If your file is not a binary file you > won't > > > be > > > > able to decode it as BSON.
> > > > If your file is a text file containing JSON you will want to parse > it a > > > > different way:
> > > > string json; // load this from your file > > > > BsonDocument document = > BsonSerializer.Deserialize<BsonDocument>(json);
> > > > On Thu, May 24, 2012 at 7:57 PM, sLaVeN <slug...@gmail.com> wrote: > > > > > Thanks Robert for the quick reply. I tried that but I am getting > an > > > > > exception.
> > > > > string bson = > File.ReadAllText(@"C:\Users\myuser\Desktop\bson.txt"); > > > > > byte[] bytesarr = Encoding.UTF8.GetBytes(bson); // Tried > different > > > > > Encoding here but that didn't seem to matter. > > > > > BsonDocument document =
Cool, that looks like it is probably bson. Here's what to do next. Take the byte array and save it to a file on disk. Then we can use the bsondump.exe in the bin directory of your mongo installation and inspect the file.
bsondump.exe {filename}
If you can, post the results here. If not, tell me if everything looks valid.
> On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com> wrote: > > Well, here's a test. Take the stream you are getting from the server, > use > > Encoding.UTF8.GetString(byetArray) and save that to a file. if it is > > legible, then it is a json string. If not, we'll go from there.
> > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> > > Hmm, I am not sure how the server is returning it to me but I would > > > assume it would be BSON because we have some other apps that do > > > similar things and display it as JSON. However, I could go with an > > > assumption that it could be JSON encoded as binary. If thats the case, > > > how would I got about decoding the Json Binary to regular JSON?
> > > Thanks
> > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com> wrote: > > > > Is the stream you are passing in encoded in BSON or is it a JSON > string > > > > encoded as binary? As in, does the stream match the bson spec here: > > >http://bsonspec.org/#/specification?
> > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > > > > Hi Robert,
> > > > > yes, there could have been an issue there because I was trying to > > > > > convert the stream to string as well as bytes array which was > giving > > > > > me those issues. However, I tried now to pass in the stream > directly > > > > > to the Deserializer and it looks like its trying to do something > but > > > > > complains about Duplicate element. There is no duplicate element. > We > > > > > have WebApp where we can make these calls and Json that Im getting > > > > > back is fine, no duplicates but when i try to do it from my C# > code, i > > > > > get the following error. Could there be a bug in the Driver? > Thanks
> > > > > On May 24, 7:29 pm, Robert Stam <rob...@10gen.com> wrote: > > > > > > BSON is a binary encoding. If your file is not a binary file you > > > won't > > > > > be > > > > > > able to decode it as BSON.
> > > > > > If your file is a text file containing JSON you will want to > parse > > > it a > > > > > > different way:
> > > > > > string json; // load this from your file > > > > > > BsonDocument document = > > > BsonSerializer.Deserialize<BsonDocument>(json);
> > > > > > On Thu, May 24, 2012 at 7:57 PM, sLaVeN <slug...@gmail.com> > wrote: > > > > > > > Thanks Robert for the quick reply. I tried that but I am
I just ran the bsondump and it seems everything is looking good now.
Unfortunately I cant post the results since its company confidential
data but if there is a way to diagrammatically do this now, that would
be job done :).
Thanks
On May 25, 2:12 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> Cool, that looks like it is probably bson. Here's what to do next. Take
> the byte array and save it to a file on disk. Then we can use the
> bsondump.exe in the bin directory of your mongo installation and inspect
> the file.
> bsondump.exe {filename}
> If you can, post the results here. If not, tell me if everything looks
> valid.
> On Friday, May 25, 2012 4:48:57 PM UTC-4, sLaVeN wrote:
> > It looks something like that once saved to File
> > On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> > > Well, here's a test. Take the stream you are getting from the server,
> > use
> > > Encoding.UTF8.GetString(byetArray) and save that to a file. if it is
> > > legible, then it is a json string. If not, we'll go from there.
> > > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> > > > Hmm, I am not sure how the server is returning it to me but I would
> > > > assume it would be BSON because we have some other apps that do
> > > > similar things and display it as JSON. However, I could go with an
> > > > assumption that it could be JSON encoded as binary. If thats the case,
> > > > how would I got about decoding the Json Binary to regular JSON?
> > > > Thanks
> > > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com> wrote:
> > > > > Is the stream you are passing in encoded in BSON or is it a JSON
> > string
> > > > > encoded as binary? As in, does the stream match the bson spec here:
> > > >http://bsonspec.org/#/specification?
> > > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > > > > > Hi Robert,
> > > > > > yes, there could have been an issue there because I was trying to
> > > > > > convert the stream to string as well as bytes array which was
> > giving
> > > > > > me those issues. However, I tried now to pass in the stream
> > directly
> > > > > > to the Deserializer and it looks like its trying to do something
> > but
> > > > > > complains about Duplicate element. There is no duplicate element.
> > We
> > > > > > have WebApp where we can make these calls and Json that Im getting
> > > > > > back is fine, no duplicates but when i try to do it from my C#
> > code, i
> > > > > > get the following error. Could there be a bug in the Driver?
> > Thanks
So if the bsondump prints good data, then I'm not sure what to say about your problem. Robert gave the way the .net driver uses to deserialize bson. BsonSerializer.Deserialize<BsonDocument>(bson) //or some other overload
Can you post the code you are using from receipt of the bson to where you are decoding it (or as much as possible)?
On Friday, May 25, 2012 7:08:30 PM UTC-4, sLaVeN wrote:
> Hi Craig,
> I just ran the bsondump and it seems everything is looking good now. > Unfortunately I cant post the results since its company confidential > data but if there is a way to diagrammatically do this now, that would > be job done :).
> Thanks
> On May 25, 2:12 pm, craiggwilson <craiggwil...@gmail.com> wrote: > > Cool, that looks like it is probably bson. Here's what to do next. > Take > > the byte array and save it to a file on disk. Then we can use the > > bsondump.exe in the bin directory of your mongo installation and inspect > > the file.
> > bsondump.exe {filename}
> > If you can, post the results here. If not, tell me if everything looks > > valid.
> > On Friday, May 25, 2012 4:48:57 PM UTC-4, sLaVeN wrote:
> > > It looks something like that once saved to File
> > > On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com> wrote: > > > > Well, here's a test. Take the stream you are getting from the > server, > > > use > > > > Encoding.UTF8.GetString(byetArray) and save that to a file. if it > is > > > > legible, then it is a json string. If not, we'll go from there.
> > > > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> > > > > Hmm, I am not sure how the server is returning it to me but I > would > > > > > assume it would be BSON because we have some other apps that do > > > > > similar things and display it as JSON. However, I could go with an > > > > > assumption that it could be JSON encoded as binary. If thats the > case, > > > > > how would I got about decoding the Json Binary to regular JSON?
> > > > > Thanks
> > > > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com> wrote: > > > > > > Is the stream you are passing in encoded in BSON or is it a JSON > > > string > > > > > > encoded as binary? As in, does the stream match the bson spec > here: > > > > >http://bsonspec.org/#/specification?
> > > > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > > > > > > Hi Robert,
> > > > > > > yes, there could have been an issue there because I was trying > to > > > > > > > convert the stream to string as well as bytes array which was > > > giving > > > > > > > me those issues. However, I tried now to pass in the stream > > > directly > > > > > > > to the Deserializer and it looks like its trying to do > something > > > but > > > > > > > complains about Duplicate element. There is no duplicate > element. > > > We > > > > > > > have WebApp where we can make these calls and Json that Im > getting > > > > > > > back is fine, no duplicates but when i try to do it from my C# > > > code, i > > > > > > > get the following error. Could there be a bug in the Driver? > > > Thanks
Stream stream = request.GetResponse().GetResponseStream();
var document =
MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(stream) ; //
Tried Byte array, string and few other types.
}
On May 25, 4:26 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> So if the bsondump prints good data, then I'm not sure what to say about
> your problem. Robert gave the way the .net driver uses to deserialize
> bson. BsonSerializer.Deserialize<BsonDocument>(bson) //or some other
> overload
> Can you post the code you are using from receipt of the bson to where you
> are decoding it (or as much as possible)?
> On Friday, May 25, 2012 7:08:30 PM UTC-4, sLaVeN wrote:
> > Hi Craig,
> > I just ran the bsondump and it seems everything is looking good now.
> > Unfortunately I cant post the results since its company confidential
> > data but if there is a way to diagrammatically do this now, that would
> > be job done :).
> > Thanks
> > On May 25, 2:12 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> > > Cool, that looks like it is probably bson. Here's what to do next.
> > Take
> > > the byte array and save it to a file on disk. Then we can use the
> > > bsondump.exe in the bin directory of your mongo installation and inspect
> > > the file.
> > > bsondump.exe {filename}
> > > If you can, post the results here. If not, tell me if everything looks
> > > valid.
> > > On Friday, May 25, 2012 4:48:57 PM UTC-4, sLaVeN wrote:
> > > > It looks something like that once saved to File
> > > > On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> > > > > Well, here's a test. Take the stream you are getting from the
> > server,
> > > > use
> > > > > Encoding.UTF8.GetString(byetArray) and save that to a file. if it
> > is
> > > > > legible, then it is a json string. If not, we'll go from there.
> > > > > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> > > > > > Hmm, I am not sure how the server is returning it to me but I
> > would
> > > > > > assume it would be BSON because we have some other apps that do
> > > > > > similar things and display it as JSON. However, I could go with an
> > > > > > assumption that it could be JSON encoded as binary. If thats the
> > case,
> > > > > > how would I got about decoding the Json Binary to regular JSON?
> > > > > > Thanks
> > > > > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com> wrote:
> > > > > > > Is the stream you are passing in encoded in BSON or is it a JSON
> > > > string
> > > > > > > encoded as binary? As in, does the stream match the bson spec
> > here:
> > > > > >http://bsonspec.org/#/specification?
> > > > > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > > > > > > > Hi Robert,
> > > > > > > > yes, there could have been an issue there because I was trying
> > to
> > > > > > > > convert the stream to string as well as bytes array which was
> > > > giving
> > > > > > > > me those issues. However, I tried now to pass in the stream
> > > > directly
> > > > > > > > to the Deserializer and it looks like its trying to do
> > something
> > > > but
> > > > > > > > complains about Duplicate element. There is no duplicate
> > element.
> > > > We
> > > > > > > > have WebApp where we can make these calls and Json that Im
> > getting
> > > > > > > > back is fine, no duplicates but when i try to do it from my C#
> > > > code, i
> > > > > > > > get the following error. Could there be a bug in the Driver?
> > > > Thanks
That looks right to me. We are going to be kinda stuck here unless you can provide us with a sample of the bson you are trying to decode, or at least an example that breaks. If you are okay providing 10gen with a copy of the data so we can debug through it, then you can create a jira issue for the project "Community Private". It will only be seen by 10gen employees. You can assign it to me, Craig Wilson and I'll look at it asap. https://jira.mongodb.org/secure/CreateIssue!default.jspa
> Tried Byte array, string and few other types. > }
> On May 25, 4:26 pm, craiggwilson <craiggwil...@gmail.com> wrote: > > So if the bsondump prints good data, then I'm not sure what to say about > > your problem. Robert gave the way the .net driver uses to deserialize > > bson. BsonSerializer.Deserialize<BsonDocument>(bson) //or some other > > overload
> > Can you post the code you are using from receipt of the bson to where > you > > are decoding it (or as much as possible)?
> > On Friday, May 25, 2012 7:08:30 PM UTC-4, sLaVeN wrote:
> > > Hi Craig,
> > > I just ran the bsondump and it seems everything is looking good now. > > > Unfortunately I cant post the results since its company confidential > > > data but if there is a way to diagrammatically do this now, that would > > > be job done :).
> > > Thanks
> > > On May 25, 2:12 pm, craiggwilson <craiggwil...@gmail.com> wrote: > > > > Cool, that looks like it is probably bson. Here's what to do next. > > > Take > > > > the byte array and save it to a file on disk. Then we can use the > > > > bsondump.exe in the bin directory of your mongo installation and > inspect > > > > the file.
> > > > bsondump.exe {filename}
> > > > If you can, post the results here. If not, tell me if everything > looks > > > > valid.
> > > > On Friday, May 25, 2012 4:48:57 PM UTC-4, sLaVeN wrote:
> > > > > It looks something like that once saved to File
> > > > > On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com> wrote: > > > > > > Well, here's a test. Take the stream you are getting from the > > > server, > > > > > use > > > > > > Encoding.UTF8.GetString(byetArray) and save that to a file. if > it > > > is > > > > > > legible, then it is a json string. If not, we'll go from there.
> > > > > > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> > > > > > > Hmm, I am not sure how the server is returning it to me but I > > > would > > > > > > > assume it would be BSON because we have some other apps that > do > > > > > > > similar things and display it as JSON. However, I could go > with an > > > > > > > assumption that it could be JSON encoded as binary. If thats > the > > > case, > > > > > > > how would I got about decoding the Json Binary to regular > JSON?
> > > > > > > Thanks
> > > > > > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com> > wrote: > > > > > > > > Is the stream you are passing in encoded in BSON or is it a > JSON > > > > > string > > > > > > > > encoded as binary? As in, does the stream match the bson > spec > > > here: > > > > > > >http://bsonspec.org/#/specification?
> > > > > > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > > > > > > > > Hi Robert,
> > > > > > > > > yes, there could have been an issue there because I was > trying > > > to > > > > > > > > > convert the stream to string as well as bytes array which > was > > > > > giving > > > > > > > > > me those issues. However, I tried now to pass in the > stream > > > > > directly > > > > > > > > > to the Deserializer and it looks like its trying to do > > > something > > > > > but > > > > > > > > > complains about Duplicate element. There is no duplicate > > > element. > > > > > We > > > > > > > > > have WebApp where we can make these calls and Json that Im > > > getting > > > > > > > > > back is fine, no duplicates but when i try to do it from > my C# > > > > > code, i > > > > > > > > > get the following error. Could there be a bug in the > Driver? > > > > > Thanks
In one of your earlier messages you mentioned that you got this exception:
Unhandled Exception: System.InvalidOperationException: Duplicate element
name 'm_fleg'
If you got that exception it would seem that you were in the process of
properly decoding a binary BSON stream but that the C# driver found a
duplicate element name (even though you don't think there are any
duplicates).
The BSON spec is silent on whether duplicate names are allowed. The various
drivers and the server differ on whether they allow duplicate names to be
created in the first place and how they respond when they encounter a
duplicate name. The C# driver is on the strict side and throws exceptions
when a duplicate element is encountered. The server often doesn't even
notice when duplicate element names are stored. Some drivers handle
duplicate names by overwriting the value with the last value encountered.
I strongly suspect that you really do have a duplicate element name, even
if you don't think you do.
On Mon, May 28, 2012 at 6:25 PM, craiggwilson <craiggwil...@gmail.com>wrote:
> That looks right to me. We are going to be kinda stuck here unless you
> can provide us with a sample of the bson you are trying to decode, or at
> least an example that breaks. If you are okay providing 10gen with a copy
> of the data so we can debug through it, then you can create a jira issue
> for the project "Community Private". It will only be seen by 10gen
> employees. You can assign it to me, Craig Wilson and I'll look at it asap.
> https://jira.mongodb.org/secure/CreateIssue!default.jspa
> Hope this will help.
> On Saturday, May 26, 2012 11:00:52 AM UTC-4, sLaVeN wrote:
>> This is sort of what I am using right now to just test it out
>> Tried Byte array, string and few other types.
>> }
>> On May 25, 4:26 pm, craiggwilson <craiggwil...@gmail.com> wrote:
>> > So if the bsondump prints good data, then I'm not sure what to say
>> about
>> > your problem. Robert gave the way the .net driver uses to deserialize
>> > bson. BsonSerializer.Deserialize<**BsonDocument>(bson) //or some
>> other
>> > overload
>> > Can you post the code you are using from receipt of the bson to where
>> you
>> > are decoding it (or as much as possible)?
>> > On Friday, May 25, 2012 7:08:30 PM UTC-4, sLaVeN wrote:
>> > > Hi Craig,
>> > > I just ran the bsondump and it seems everything is looking good now.
>> > > Unfortunately I cant post the results since its company confidential
>> > > data but if there is a way to diagrammatically do this now, that
>> would
>> > > be job done :).
>> > > Thanks
>> > > On May 25, 2:12 pm, craiggwilson <craiggwil...@gmail.com> wrote:
>> > > > Cool, that looks like it is probably bson. Here's what to do next.
>> > > Take
>> > > > the byte array and save it to a file on disk. Then we can use the
>> > > > bsondump.exe in the bin directory of your mongo installation and
>> inspect
>> > > > the file.
>> > > > bsondump.exe {filename}
>> > > > If you can, post the results here. If not, tell me if everything
>> looks
>> > > > valid.
>> > > > On Friday, May 25, 2012 4:48:57 PM UTC-4, sLaVeN wrote:
>> > > > > It looks something like that once saved to File
>> > > > > On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com> wrote:
>> > > > > > Well, here's a test. Take the stream you are getting from the
>> > > server,
>> > > > > use
>> > > > > > Encoding.UTF8.GetString(**byetArray) and save that to a file.
>> if it
>> > > is
>> > > > > > legible, then it is a json string. If not, we'll go from
>> there.
>> > > > > > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
>> > > > > > > Hmm, I am not sure how the server is returning it to me but I
>> > > would
>> > > > > > > assume it would be BSON because we have some other apps that
>> do
>> > > > > > > similar things and display it as JSON. However, I could go
>> with an
>> > > > > > > assumption that it could be JSON encoded as binary. If thats
>> the
>> > > case,
>> > > > > > > how would I got about decoding the Json Binary to regular
>> JSON?
>> > > > > > > Thanks
>> > > > > > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com>
>> wrote:
>> > > > > > > > Is the stream you are passing in encoded in BSON or is it a
>> JSON
>> > > > > string
>> > > > > > > > encoded as binary? As in, does the stream match the bson
>> spec
>> > > here:
>> > > > > > >http://bsonspec.org/#/**specification<http://bsonspec.org/#/specification>?
>> > > > > > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
>> > > > > > > > > Hi Robert,
>> > > > > > > > > yes, there could have been an issue there because I was
>> trying
>> > > to
>> > > > > > > > > convert the stream to string as well as bytes array which
>> was
>> > > > > giving
>> > > > > > > > > me those issues. However, I tried now to pass in the
>> stream
>> > > > > directly
>> > > > > > > > > to the Deserializer and it looks like its trying to do
>> > > something
>> > > > > but
>> > > > > > > > > complains about Duplicate element. There is no duplicate
>> > > element.
>> > > > > We
>> > > > > > > > > have WebApp where we can make these calls and Json that
>> Im
>> > > getting
>> > > > > > > > > back is fine, no duplicates but when i try to do it from
>> my C#
>> > > > > code, i
>> > > > > > > > > get the following error. Could there be a bug in the
>> Driver?
>> > > > > Thanks
I just double check and yes indeed, there are some duplicate elements.
Now I downloaded the source code and I do see that you guys have a
flag to allow duplicate elements. How can I use this flag to allow
duplicate elements? I think that would solve the problem.
Thanks
On May 28, 3:56 pm, Robert Stam <rob...@10gen.com> wrote:
> In one of your earlier messages you mentioned that you got this exception:
> Unhandled Exception: System.InvalidOperationException: Duplicate element
> name 'm_fleg'
> If you got that exception it would seem that you were in the process of
> properly decoding a binary BSON stream but that the C# driver found a
> duplicate element name (even though you don't think there are any
> duplicates).
> The BSON spec is silent on whether duplicate names are allowed. The various
> drivers and the server differ on whether they allow duplicate names to be
> created in the first place and how they respond when they encounter a
> duplicate name. The C# driver is on the strict side and throws exceptions
> when a duplicate element is encountered. The server often doesn't even
> notice when duplicate element names are stored. Some drivers handle
> duplicate names by overwriting the value with the last value encountered.
> I strongly suspect that you really do have a duplicate element name, even
> if you don't think you do.
> On Mon, May 28, 2012 at 6:25 PM, craiggwilson <craiggwil...@gmail.com>wrote:
> > That looks right to me. We are going to be kinda stuck here unless you
> > can provide us with a sample of the bson you are trying to decode, or at
> > least an example that breaks. If you are okay providing 10gen with a copy
> > of the data so we can debug through it, then you can create a jira issue
> > for the project "Community Private". It will only be seen by 10gen
> > employees. You can assign it to me, Craig Wilson and I'll look at it asap.
> > https://jira.mongodb.org/secure/CreateIssue!default.jspa
> > Hope this will help.
> > On Saturday, May 26, 2012 11:00:52 AM UTC-4, sLaVeN wrote:
> >> This is sort of what I am using right now to just test it out
> >> Tried Byte array, string and few other types.
> >> }
> >> On May 25, 4:26 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> >> > So if the bsondump prints good data, then I'm not sure what to say
> >> about
> >> > your problem. Robert gave the way the .net driver uses to deserialize
> >> > bson. BsonSerializer.Deserialize<**BsonDocument>(bson) //or some
> >> other
> >> > overload
> >> > Can you post the code you are using from receipt of the bson to where
> >> you
> >> > are decoding it (or as much as possible)?
> >> > On Friday, May 25, 2012 7:08:30 PM UTC-4, sLaVeN wrote:
> >> > > Hi Craig,
> >> > > I just ran the bsondump and it seems everything is looking good now.
> >> > > Unfortunately I cant post the results since its company confidential
> >> > > data but if there is a way to diagrammatically do this now, that
> >> would
> >> > > be job done :).
> >> > > Thanks
> >> > > On May 25, 2:12 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> >> > > > Cool, that looks like it is probably bson. Here's what to do next.
> >> > > Take
> >> > > > the byte array and save it to a file on disk. Then we can use the
> >> > > > bsondump.exe in the bin directory of your mongo installation and
> >> inspect
> >> > > > the file.
> >> > > > bsondump.exe {filename}
> >> > > > If you can, post the results here. If not, tell me if everything
> >> looks
> >> > > > valid.
> >> > > > On Friday, May 25, 2012 4:48:57 PM UTC-4, sLaVeN wrote:
> >> > > > > It looks something like that once saved to File
> >> > > > > On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> >> > > > > > Well, here's a test. Take the stream you are getting from the
> >> > > server,
> >> > > > > use
> >> > > > > > Encoding.UTF8.GetString(**byetArray) and save that to a file.
> >> if it
> >> > > is
> >> > > > > > legible, then it is a json string. If not, we'll go from
> >> there.
> >> > > > > > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> >> > > > > > > Hmm, I am not sure how the server is returning it to me but I
> >> > > would
> >> > > > > > > assume it would be BSON because we have some other apps that
> >> do
> >> > > > > > > similar things and display it as JSON. However, I could go
> >> with an
> >> > > > > > > assumption that it could be JSON encoded as binary. If thats
> >> the
> >> > > case,
> >> > > > > > > how would I got about decoding the Json Binary to regular
> >> JSON?
> >> > > > > > > Thanks
> >> > > > > > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com>
> >> wrote:
> >> > > > > > > > Is the stream you are passing in encoded in BSON or is it a
> >> JSON
> >> > > > > string
> >> > > > > > > > encoded as binary? As in, does the stream match the bson
> >> spec
> >> > > here:
> >> > > > > > >http://bsonspec.org/#/**specification<http://bsonspec.org/#/specification>?
> >> > > > > > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> >> > > > > > > > > Hi Robert,
> >> > > > > > > > > yes, there could have been an issue there because I was
> >> trying
> >> > > to
> >> > > > > > > > > convert the stream to string as well as bytes array which
> >> was
> >> > > > > giving
> >> > > > > > > > > me those issues. However, I tried now to pass in the
> >> stream
> >> > > > > directly
> >> > > > > > > > > to the Deserializer and it looks like its trying to do
> >> > > something
> >> > > > > but
> >> > > > > > > > > complains about Duplicate element. There is no duplicate
> >> > > element.
> >> > > > > We
> >> > > > > > > > > have WebApp where we can make these calls and Json that
> >> Im
> >> > > getting
> >> > > > > > > > > back is fine, no duplicates but when i try to do it from
> >> my C#
> >> > > > > code, i
> >> > > > > > > > > get the following error. Could there be a bug in the
> >> Driver?
> >> > > > > Thanks
I would strongly recommend that you never allow duplicate element names to
occur. They behave differently in different situations and lead to
unpredictable outcomes.
However, in the C# driver you can tell it to always allow duplicate names
during deserialization if you want to. I would recommend you use this
technique only while cleaning up the data.
I created a test document with duplicate elements like this:
var server = MongoServer.Create("mongodb://localhost/?safe=true");
var database = server.GetDatabase("test");
var collection = database.GetCollection("test");
var document = new BsonDocument(true)
{
{ "x", 1 },
{ "x", 2 },
{ "embedded", new BsonDocument(true)
{
{ "y", 1 },
{ "y", 2 }
}
}
};
collection.Drop();
collection.Insert(document);
You can read documents with duplicate elements like this:
But keep in mind that setting DocumentSerializationOptions.Defaults is a
global setting and should only be done once when the program is starting
up. Manipulating DocumentSerializationOptions.Defaults back and forth
between different values is not thread safe (which may not be an issue if
your program is single threaded).
On Tue, May 29, 2012 at 9:01 PM, sLaVeN <slug...@gmail.com> wrote:
> I just double check and yes indeed, there are some duplicate elements.
> Now I downloaded the source code and I do see that you guys have a
> flag to allow duplicate elements. How can I use this flag to allow
> duplicate elements? I think that would solve the problem.
> Thanks
> On May 28, 3:56 pm, Robert Stam <rob...@10gen.com> wrote:
> > In one of your earlier messages you mentioned that you got this
> exception:
> > Unhandled Exception: System.InvalidOperationException: Duplicate element
> > name 'm_fleg'
> > If you got that exception it would seem that you were in the process of
> > properly decoding a binary BSON stream but that the C# driver found a
> > duplicate element name (even though you don't think there are any
> > duplicates).
> > The BSON spec is silent on whether duplicate names are allowed. The
> various
> > drivers and the server differ on whether they allow duplicate names to be
> > created in the first place and how they respond when they encounter a
> > duplicate name. The C# driver is on the strict side and throws exceptions
> > when a duplicate element is encountered. The server often doesn't even
> > notice when duplicate element names are stored. Some drivers handle
> > duplicate names by overwriting the value with the last value encountered.
> > I strongly suspect that you really do have a duplicate element name, even
> > if you don't think you do.
> > On Mon, May 28, 2012 at 6:25 PM, craiggwilson <craiggwil...@gmail.com
> >wrote:
> > > That looks right to me. We are going to be kinda stuck here unless you
> > > can provide us with a sample of the bson you are trying to decode, or
> at
> > > least an example that breaks. If you are okay providing 10gen with a
> copy
> > > of the data so we can debug through it, then you can create a jira
> issue
> > > for the project "Community Private". It will only be seen by 10gen
> > > employees. You can assign it to me, Craig Wilson and I'll look at it
> asap.
> > > https://jira.mongodb.org/secure/CreateIssue!default.jspa
> > > Hope this will help.
> > > On Saturday, May 26, 2012 11:00:52 AM UTC-4, sLaVeN wrote:
> > >> This is sort of what I am using right now to just test it out
> > >> Tried Byte array, string and few other types.
> > >> }
> > >> On May 25, 4:26 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> > >> > So if the bsondump prints good data, then I'm not sure what to say
> > >> about
> > >> > your problem. Robert gave the way the .net driver uses to
> deserialize
> > >> > bson. BsonSerializer.Deserialize<**BsonDocument>(bson) //or some
> > >> other
> > >> > overload
> > >> > Can you post the code you are using from receipt of the bson to
> where
> > >> you
> > >> > are decoding it (or as much as possible)?
> > >> > On Friday, May 25, 2012 7:08:30 PM UTC-4, sLaVeN wrote:
> > >> > > Hi Craig,
> > >> > > I just ran the bsondump and it seems everything is looking good
> now.
> > >> > > Unfortunately I cant post the results since its company
> confidential
> > >> > > data but if there is a way to diagrammatically do this now, that
> > >> would
> > >> > > be job done :).
> > >> > > Thanks
> > >> > > On May 25, 2:12 pm, craiggwilson <craiggwil...@gmail.com> wrote:
> > >> > > > Cool, that looks like it is probably bson. Here's what to do
> next.
> > >> > > Take
> > >> > > > the byte array and save it to a file on disk. Then we can use
> the
> > >> > > > bsondump.exe in the bin directory of your mongo installation and
> > >> inspect
> > >> > > > the file.
> > >> > > > bsondump.exe {filename}
> > >> > > > If you can, post the results here. If not, tell me if
> everything
> > >> looks
> > >> > > > valid.
> > >> > > > On Friday, May 25, 2012 4:48:57 PM UTC-4, sLaVeN wrote:
> > >> > > > > It looks something like that once saved to File
> > >> > > > > On May 25, 1:38 pm, craiggwilson <craiggwil...@gmail.com>
> wrote:
> > >> > > > > > Well, here's a test. Take the stream you are getting from
> the
> > >> > > server,
> > >> > > > > use
> > >> > > > > > Encoding.UTF8.GetString(**byetArray) and save that to a
> file.
> > >> if it
> > >> > > is
> > >> > > > > > legible, then it is a json string. If not, we'll go from
> > >> there.
> > >> > > > > > On Friday, May 25, 2012 4:16:28 PM UTC-4, sLaVeN wrote:
> > >> > > > > > > Hmm, I am not sure how the server is returning it to me
> but I
> > >> > > would
> > >> > > > > > > assume it would be BSON because we have some other apps
> that
> > >> do
> > >> > > > > > > similar things and display it as JSON. However, I could go
> > >> with an
> > >> > > > > > > assumption that it could be JSON encoded as binary. If
> thats
> > >> the
> > >> > > case,
> > >> > > > > > > how would I got about decoding the Json Binary to regular
> > >> JSON?
> > >> > > > > > > Thanks
> > >> > > > > > > On May 25, 11:44 am, craiggwilson <craiggwil...@gmail.com
> > >> wrote:
> > >> > > > > > > > Is the stream you are passing in encoded in BSON or is
> it a
> > >> JSON
> > >> > > > > string
> > >> > > > > > > > encoded as binary? As in, does the stream match the
> bson
> > >> spec
> > >> > > here:
> > >> > > > > > >http://bsonspec.org/#/**specification<
> http://bsonspec.org/#/specification>?
> > >> > > > > > > > On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:
> > >> > > > > > > > > Hi Robert,
> > >> > > > > > > > > yes, there could have been an issue there because I
> was
> > >> trying
> > >> > > to
> > >> > > > > > > > > convert the stream to string as well as bytes array
> which
> > >> was
> > >> > > > > giving
> > >> > > > > > > > > me those issues. However, I tried now to pass in the
> > >> stream
> > >> > > > > directly
> > >> > > > > > > > > to the Deserializer and it looks like its trying to do
> > >> > > something
> > >> > > > > but
> > >> > > > > > > > > complains about Duplicate element. There is no
> duplicate
> > >> > > element.
> > >> > > > > We
> > >> > > > > > > > > have WebApp where we can make these calls and Json
> that
> > >> Im
> > >> > > getting
> > >> > > > > > > > > back is fine, no duplicates but when i try to do it
> from
> > >> my C#
> > >> > > > > code, i
> > >> > > > > > > > > get the following error. Could there be a bug in the
> > >> Driver?
> > >> > > > > Thanks