B4J Question JavaObject, calling the java class method.

Hanz

Active Member
Greetings everyone,

How do you call the following code under the .RunMethod of a JavaObject:

myDoc = collection.find(eq("i", 71)).first();

The above code is an example given for mongodb tutorial in Java.

I tried the following code in B4J to follow the above code:

cursor = empCollection.RunMethod("find", _
Array As Object(eq.RunMethod("eq", Array As Object("_id", 1))))

cursor.RunMethod("first", Null)


And what I have got when I run the log(cursor) is the following:

(FindIterableImpl) com.mongodb.client.internal.FindIterableImpl@27005223


Thanks.
 

stevel05

Expert
Licensed User
Longtime User
It's difficult to be certain without being able to test it but If cursor is some kind of iterable list, you seem to be nearly there.

Try changing the second line to:

B4X:
myDoc = cursor.RunMethod("first", Null)

I don't know what the type myDoc should be, is should be in the documentation.
 
Last edited:
Upvote 0

Hanz

Active Member
It's difficult to be certain without being able to test it but If cursor is some kind of iterable list, you seem to be nearly there.

Try changing the second line to:

B4X:
myDoc = cursor.RunMethod("first", Null)

I don't know what the type myDoc should be, is should be in the documentation.

The cursor which I used is a bson document type: cursor.InitializeNewInstance("org.bson.Document", Null)

I also tried this: cursor.InitializeStatic("com.mongodb.client.MongoCursor")

And I'm getting the same result.
 
Upvote 0

Hanz

Active Member
Hey, thanks for the reply. I already resolved the issue above. As to the official library, it's based on java driver ver. 3.3. I need the java driver 3.8.x. I need the "Transactions(ACID)" and the "Change streams" features. I hope it will be updated.
 
Upvote 0
Top