B4J Question [MongoDB]Get last inserted getObjectId("_id")

Duque

Active Member
Licensed User
Longtime User
Hi, I hope you can give me a hand.
Inserting a document into a MongoDB collection:
Main.db.GetCollection(collection).Insert(documentList)
I hope to get the last inserted ObjectId...
How is it done?
 

teddybear

Well-Known Member
Licensed User
In short, I need to find the last sorted id and limit it to 1.

Is it you want?

B4X:
Dim res As List = Main.db.GetCollection(collection).Find2(Null, Null, CreateMap("_id":-1),0,1)
Log(res.Get(0))
 
Upvote 0
Top