v2kiran / PSLiteDB

PowerShell wrapper for LiteDB
MIT License
52 stars 6 forks source link

Array of complex objects is lost on save #6

Closed rdbartram closed 4 years ago

rdbartram commented 4 years ago

I'm having the issue that when an array of say either hashtables or pscustomobjects is saved to a document, upon get, there is only one item :(.

example

$obj = [pscustomobject]@{
    prop = @(@{obb=123}),@{test=123})
    _id="1"
} | ConvertTo-LiteDbBSON

Add-LiteDBDocument -Collection test - Document $obj

Find-LiteDBDocument -Collection test

Collection        _id prop
----------        --- ----
test 2   @{Collection=test; test=123}               # pscustomobject example
test 1   {1,2,3}                                                    # hashtable example

Any help here would be appreciated.

thanks

v2kiran commented 4 years ago

this looks like an issue with handling arrays while constructing the psobject. When you check the db with the litedb gui does the array of hash tables show up under the prop array?

v2kiran commented 4 years ago

this has been implemented in the latest version.

The nested BSON is serialized to Json and then de-serialized to psobjects. There is performance hit due to 'convertfrom-json' being used but that was the easiest to implement and it works. If there is a better way I would appreciate contributions.