Re: MongoDB Updates from different clients?

17 views
Skip to first unread message

Polar Humenn

unread,
Mar 28, 2013, 2:58:52 PM3/28/13
to mongo...@googlegroups.com
A little more info: If I'm running a linux version of the mongo client (not the Rails console) and I query for the
Document. If I use App2 to update the Document  and query with the same mongo client, I get back the updated 
answer immediately. 

This situation would lead one to believe that something is up with the Ruby MongoMapper or Mongo drivers.
Any clues?

On Thursday, March 28, 2013 2:15:02 PM UTC-4, Polar Humenn wrote:
I'm using a MongoLab DB for a rails project, and using Mongo 1.8.3, and MongoMapper 11.2, and effectively
I'm sharing that database between 2 different apps.

1. I get the value of Document by looking at it's page on App 1.
2. On App 2, I edit said document, and update. 
3. App 1 does not see the change, no matter how many times I make requests for it.

Further, inside App1  I also issue a @doc.reload call, and still the same. The Mongo Drvier logger "seems" to
be logging reads from the DB for the first call and the second call.

I assume the IdentityMap is getting cleared between requests, and I've also explicitly called that before retrieving
the document.

I'm at a loss. The only way App 1 gets the updated document is when I stop and restart the server.

This happens in the Rails console as well, even after a global reload! In order to see the change, I must stop and restart the console.

Am I missing some configuration parameter? Or is the it the MongoLab DB that is holding onto what should be an outdated cache for a particular connection?

Thanks for any ideas?

Cheers,
-Polar

Kevin Lawver

unread,
Mar 28, 2013, 3:00:58 PM3/28/13
to mongo...@googlegroups.com
I'd try disabling IdentityMap altogether and see what happens.  If you get the updated version, then it's not getting cleared between requests.

Polar Humenn

unread,
Mar 28, 2013, 3:36:32 PM3/28/13
to mongo...@googlegroups.com
I think  the problem *may* be with associations? At this point, I must assume that a @doc.reload call does not reload its subordinates.

However, it looks that even if you do clear the IdentityMap, an association will keep

My code:

def show
   MongoMapper::Plugins::IdentityMap.clear                # cut and pasted from MongMapper.Middleware::IdentityMap
   @doc = Cms::Page.find(params[:id])
    puts ("Document #{@doc} #{@doc.id")
end

Successive calls leads to the following output:

Document #<Cms::Page:0x000000087f4b78> 50dbbf5c0654650002000005

Document #<Cms::Page:0x000000087f4b78> 50dbbf5c0654650002000005

Document #<Cms::Page:0x000000087f4b78> 50dbbf5c0654650002000005

Which would lead one to believe that the IdentityMap isn't getting cleared, even when it is explicitly called!

Nothing that reload doesn't go after subordinate associations, I've solved my problem by:

      @doc.blocks.all.map {|x| x.reload}

But this is a shaky solution at best. Ugg. I shouldn't have to do this if the identity map were cleared. Right?

Cheers,
-Polar

Polar Humenn

unread,
Mar 28, 2013, 4:50:20 PM3/28/13
to mongo...@googlegroups.com
Also, something like this didn't work.

doc = Cms::Page.find(params[id])
doc.layout
doc.layout.reload

Both "layouts" yield the same values although the "layout" has been updated. Grrrrr. Reload didn't even work.

However, I do something in this order:
1. doc.layout
2. doc.layout.reload
3. layout = Cms::Layout.find(doc.layout.id)
4. layout.reload

The only one that gets the update is #4. And printouts show that they are all the same memory object.
Could somebody please explain this to me?

I'd really like not to have to take everything apart and reload everything piece and bit of everything. Uggg.
I guess I don't understand this IdentityMap.
Reply all
Reply to author
Forward
0 new messages