Hello team, am new to mongodb and am using it for...
# kmongo
i
Hello team, am new to mongodb and am using it for my ktor project. How can i return the inserted document back to client after insertion. I need the doc to store it in room
s
You could use this method and make sure to set options to upsert and return new document https://litote.org/kmongo/dokka/kmongo/org.litote.kmongo/com.mongodb.client.-mongo-collection/find-one-and-update.html
i
I have managed to insert document into my Db but when i return the insertedId, its coming out null. The acknowledgement was made but id is null.how is that possible?
s
As you used insert it returns only Id so to be able to return full document you either have to build it with Id or you have to use trick with
findoneandupdate
i
I want to get the id of the inserted document so that i can use the trick. but my insertId returns null. In my user POJO i have initialised @Bson val id:String= ObjectId.toString() Could this be the problem?How do i fix it.
Finaly found a work around on the issue. Regarding retrieving the id from the inserted document after acknowledgement, you have to make an insertion then after the acknowledgement, retrieve the inserted id through another query using anotger unique field. Normally the inserted document returns a Boolean of acknowledgement and the insertedId. But you will notice that the insertedId is null even when acknowledgement is true.