简体   繁体   中英

Scala - Get Last Inserted ObjectId Using Casbah MongoDB

Is there any way to get last inserted ObjectId? i can't find it on their documentation or maybe i am not digging far enough, thanks.

The insert method will mutate the underlying DBObject and add a _id field if it doesn't exist.

> val document = MongoDBObject("{x: 101}")
> collection.insert(document)
> println(document)

{ "x" : 101 , "_id" : { "$oid" : "58204e47e9dd35767edb0225"}}

So you can check your inserted document for the _id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM