v2kiran / PSLiteDB

PowerShell wrapper for LiteDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ConvertTo-LiteDbBSON failed to serialise '_id' in ObjectID type

Mouth7505 opened this issue · comments

Description

I have an issue with $array | ConvertTo-LiteDbBSON -As Array, where the array items has _id in ObjectID type, ObjectID type is the default index type when the LiteDB is created by New-LiteDBCollection

Reference: LiteDB / Data Structure / Objectid (https://www.litedb.org/docs/data-structure/#objectid)

Expected Behavior

# 1. Connect to LiteDB, find some document, save to an variable
Open-LiteDbConnection -Database $DBPath -Credential $DBCred
$array = Find-LiteDBDocument -Collection $DBCollection -Limit 2

# Example values
array[0]
_id: 63802bc8ac6e08130fe7df92
name: Apple

# 2. Update an item in the array
$array[0].name = 'Banana'

# 3. Push update to DB
$array_BSON = $array | ConvertTo-LiteDbBSON -As Array
Update-LiteDBDocument -Collection $DBCollection -BsonDocumentArray $array_BSON

Actual Behavior

$array_BSON = $array | ConvertTo-LiteDbBSON -As Array
WARNING: Unable to convert value [[_id, {"Timestamp":1669344201,"Machine":11300360,"Pid":4879,"Increment":15227919,"CreationTime":"2022-11-25T02:43:21Z"}]] to datetime
  1. Update-LiteDBDocument does not throw warnings of _id not found
  2. DB not updated

Specifications

  • Version: PSLiteDB committed on 2022 Feb 13 (latest as of writing)
  • Platform: Powershell 7.3.0
  • Subsystem: