Hi Holger, 

by default, BSON should be decoding a ByteArray (if persisted as is) with data 
type “binary data”, and you should be receiving a ByteArray as expected when 
reading. 
This is how SmalltalkHub works so I suspect there is something else going on 
(otherwise, there would be many, many people angry :P). 
Can you confirm the code is being persisted as binary data? (just check in the 
database).

A simple workaround is to define an accessor: 

MyClass class>>#myByteArray
        <mongoDescription>

        ^ VOMongoToOneDescription new
                attributeName: ‘byteArray';
                accessor: (MAPluggableAccessor 
                         read: [ :anObject | anObject byteArray  ] 
                         write: [ :anObject :value | anObject byteArray: value 
asByteArray ]);          
                yourself

cheers,
Esteban

> On 04 Sep 2015, at 19:51, Holger Freyther <[email protected]> wrote:
> 
> Hi all,
> 
> it is the first time I notice this and I am not sure that this has been 
> written down somewhere
> and if it is known to others (and then what to do about it).
> 
> I had an Object with a ByteArray and then tried to find this object using the 
> ByteArray and
> it wasn’t found. It looks like the ByteArray will be converted to an “array”. 
> When searching
> the ByteArray would not match it, an Array matches it. When using anArray to 
> find the object
> and using a “getter” to get the value and comparing it will not lead to 
> equality. I understand
> that Mongo doesn’t have same types (Array, OrderedCollection, ByteArray) as 
> Smalltalk but
> I wonder if there can be done something to improve the situation?
> 
> Is this known? Can we improve it? I can of course workaround it by converting 
> it to an
> array/orderedcollection before comparing it.
> 
> holger
> 
> 
> Example:
> 
> | data repository test res |
> repository := VOMongoRepository database: 'dbtest'.
> data := #[1 2 3 4].
> test := ZEByteArrayVoyage new.
> test byteArray: data.
> repository save: test.
> 
> res := repository selectOne: ZEByteArrayVoyage where: [:each | each byteArray 
> = data ].
> res.  "---> UndefinedObject"
>       
> res := repository selectOne: ZEByteArrayVoyage where: [:each | each byteArray 
> = data asArray].
> res.  "---> ZEByteArrayVoyage"
>       
> res byteArray = data. “false.. OrderedCollection = ByteArray"
> res byteArray = data asArray. “OrderedCollection = Array"
> res byteArray = data asOrderedCollection. "true"


Reply via email to