How do I go about doing this with just a single query? What I need is to fetch the newly inserted record so that I have access to its ObjectId
What I have currently is the following:
userCollection.insert(encryptedUser).map { _ =>
Right(user)
}.recover {
case l: WriteResult =>
if (l.code contains 11000)
Left(ServiceError("Email already exists"))
else
Left(ServiceError(l.errmsg.getOrElse("failure!")))
}
The user reference that I return in the Right type is the incoming request to this method and it does not contain the ObjectId as this ObjectId would be generated by the MongoDB system.