I try to use the ObjectId made from MongoDb to find some record but I' can't retreive any info.
I've use the following code but no return value
B4X:
Sub Find
Private l As List
l.Initialize
Private ar() As String
ar = Array As String ("ObjetctId('5ac65c19d4adb22e305b9f27')")
l=Inventory.find(CreateMap("_id": CreateMap( "$in": ar)),Null,Null)
For Each items As String In l
Log (items)
Next
End Sub
I've also use this code but no return value either
B4X:
Private l As List
l.Initialize
l= Inventory.Find(CreateMap("_id" : "5ac65c19d4adb22e305b9f27"),Null,Null)
For Each items As String In l
Log (items)
Next
End Sub
I can use the find method for any other records but I can't use it with the _id to find a record.
What do I miss?
Never initialize a variable and then assign a different object to it:
B4X:
Dim ar() As String = Array As String ("ObjetctId('5ac65c19d4adb22e305b9f27')")
Dim l As List = Inventory.find(CreateMap("_id": CreateMap( "$in": ar)),Null,Null)
You need to use MongoClient.StringToObjectId:
B4X:
Dim l As List = Inventory.find(CreateMap("_id": CreateMap( "$in": Array(client.StringToObjectId("5ac65c19d4adb22e305b9f27")))),Null,Null)
Many thanks for the advice.
For the MongoClient, everythink was clear but I had forgot to read all the documentation about Jmongo.
Likely be in hurry to code