字段“_id”上的 BSON 数据类型无效 'Null'
Invalid BSON data type 'Null' on field '_id'
与 类似,我正在尝试 LiteDB 文档中的示例,但在运行时出现错误:
Invalid BSON data type 'Null' on field '_id'.
我的代码如下,包括我解决问题的尝试,即添加从注释中提取的 _id 和 Id 声明 on the github, here
Public Class Customer
Public _id As LiteDB.BsonValue
Public Id As Integer
Public Name As String
Public Phones As String
Public IsActive As Boolean
End Class
Public Class ThisAddIn
Shared Sub testSub()
Dim db As New LiteDB.LiteDatabase(Directory.GetCurrentDirectory() & "\DEPDB.db")
Dim col As LiteDB.LiteCollection(Of Customer)
col = db.GetCollection(Of Customer)("customer")
Dim tCustomer As New Customer
tCustomer.Id = 1
tCustomer.Name = "John Doe"
tCustomer.Phones = "12354534"
tCustomer.IsActive = True
col.Insert(tCustomer)
end sub
end class
将 class 声明稍微更改为:
Public Class Customer
Public Property Id As Integer
Public Property Name As String
Public Phones As String
Public IsActive As Boolean
End Class
允许代码编译和 运行,并且 "Name" 字段可使用以下搜索:
col.EnsureIndex(Function(x) x.Name)
Dim tresult = col.FindOne(Function(x) x.Name.Contains("Jo"))
MsgBox(tresult.Name)
不过,我完全是偶然发现了这个解决方案,在声明中添加了文字...任何解释都将不胜感激。
与
Invalid BSON data type 'Null' on field '_id'.
我的代码如下,包括我解决问题的尝试,即添加从注释中提取的 _id 和 Id 声明 on the github, here
Public Class Customer
Public _id As LiteDB.BsonValue
Public Id As Integer
Public Name As String
Public Phones As String
Public IsActive As Boolean
End Class
Public Class ThisAddIn
Shared Sub testSub()
Dim db As New LiteDB.LiteDatabase(Directory.GetCurrentDirectory() & "\DEPDB.db")
Dim col As LiteDB.LiteCollection(Of Customer)
col = db.GetCollection(Of Customer)("customer")
Dim tCustomer As New Customer
tCustomer.Id = 1
tCustomer.Name = "John Doe"
tCustomer.Phones = "12354534"
tCustomer.IsActive = True
col.Insert(tCustomer)
end sub
end class
将 class 声明稍微更改为:
Public Class Customer
Public Property Id As Integer
Public Property Name As String
Public Phones As String
Public IsActive As Boolean
End Class
允许代码编译和 运行,并且 "Name" 字段可使用以下搜索:
col.EnsureIndex(Function(x) x.Name)
Dim tresult = col.FindOne(Function(x) x.Name.Contains("Jo"))
MsgBox(tresult.Name)
不过,我完全是偶然发现了这个解决方案,在声明中添加了文字...任何解释都将不胜感激。