No Insert in collection but got insert confirmation

79 views
Skip to first unread message

Olivier Droz

unread,
May 10, 2016, 5:24:32 AM5/10/16
to ReactiveMongo - http://reactivemongo.org

Hi All, 
I'm struggeling with an issue for a couple of weeks now and I can't figure it out. 
On the application front-end, I'm trying to generate an API token so that my users can have access to my application data from another app (salesforce for instance). 
When hitting generate, it creates a API key and stores it at 2 places: at the account/project level for a quick access and in the authentication collection.

The token is correctly updated at account level, but is not inserted in the authentication database ANYMORE! It worked 4 times and now we can't store a token in this database anymore. Note that in the same collection, I'm storing cookie and httpheader authenticators which is working fine.
Of course it works properly on my local machine and on the staging (release candidate) environment - note that the mongodb version of these 2 environments is 3.0.8 while the prod environment is 2.6

I'm using scala with reactivemongo 
I've tried many different options: 
1) update with upsert = true - (as for cookie and httpHeader authenticators) 
2) inserting scala object with a BSON serializer 
3) inserting a raw BSONDocument 
4) inserting a Json Object


Moreover, I get the confirmation that the insert succeeded. 


Here is a piece of my code (version 4 with Json Object) - works fine on localhost and RC: 


val authenticator = Json.obj("id" -> id, "user" -> user, "expirationDate" -> exp.getMillis, "lastUsed" -> last.getMillis, "creationDate" -> create.getMillis)

   
Logger.debug("Generated authenticator for API token: " + authenticator)

    collection
.insert(authenticator).onComplete {

     
case Failure(e) =>

       
Logger.error("API TOKEN NOT SAVED "+e)

       
throw e

     
case Success(writeResult) =>

       
Logger.info(s"successfully inserted API token with result: $writeResult")

   
}


I get the logger: 

> Generated authenticator for API token

AND

[info] application - successfully inserted API token with result: reactivemongo.api.commands.DefaultWriteResult: DatabaseException['<none>']


But nothing has been inserted in the DB - What should I do?

Is that the right way to insert and verify the insert in the collection?

I'm hosting my DB on mLab, but they haven't been able to help me so far...


Thanks a lot for your help, 


Olivier


Cédric Chantepie

unread,
May 11, 2016, 3:18:57 AM5/11/16
to ReactiveMongo - http://reactivemongo.org
Which RM version? Do you have debuged the write result, which seems to hold a DatabaseException ?

Olivier Droz

unread,
May 12, 2016, 4:23:02 AM5/12/16
to reacti...@googlegroups.com
Hi Cédric,
I'm using 0.11.7.play23

Database exception is empty. 

I solved it....finally

I think the mistake I did in the beginning was that I was clearing any exiting token for this user with a "collection.remove", then computed a new auth Token and inserted in in the db. 

I changed it by removing the "remove" call and replacing the insert by an update(upsert=true) and this works fine. 

Looks like the remove -> insert in much better managed in mongo3.0 than in mongo 2.6

Best regards, 
Olivier





Olivier Droz
Ing. Inf. Dipl. EPF
Rte de la Feuillère 29
1010 Lausanne

On Wed, May 11, 2016 at 9:18 AM, Cédric Chantepie <chantep...@gmail.com> wrote:
Which RM version? Do you have debuged the write result, which seems to hold a DatabaseException ?

--
You received this message because you are subscribed to a topic in the Google Groups "ReactiveMongo - http://reactivemongo.org" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/reactivemongo/SbEC3g1XXnk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to reactivemong...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages