v2kiran / PSLiteDB

PowerShell wrapper for LiteDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array of complex objects is lost on save

rdbartram opened this issue · comments

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

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?

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.