Quantcast

MongoDB GORM connects with server but times out

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

MongoDB GORM connects with server but times out

Robert La Ferla
I am trying to do a simple query against a remote MongoDB database and it is hanging.  Is there a way to turn on debugging either client or server side to see what is being sent in the request and what is being sent back?  I am able to access the remote database using the command-line "mongo" client so I don't think this is anything related to networking.  In fact, when I run my Grails app, I can see that it makes a connection with the mongod server.  The command line request also returns the record whereas Grails waits and then times out.

Person.groovy

String person_id;
String name;

def res = Person.findByPerson_id("x-123-456-xyz");

Ideas?


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MongoDB GORM connects with server but times out

Robert La Ferla-2
My primary key is a string and not a number.  Could that be the issue?  I can't find many source code examples out there on this.  If you are using Mongo and Grails, I'd like to know if you are able to have records where the primary identifier is a string.

Also, I turned on verbose logging on the mongod server (-vv) and it did show the query.  I'm stumped for now.  I am using Grails 2.0.1 and MongoDB GORM 1.0.0.RC4.  Maybe I should try another version or perhaps the Morphia one?

Thanks in advance!

On Feb 28, 2012, at 7:31 PM, Robert La Ferla wrote:

> I am trying to do a simple query against a remote MongoDB database and it is hanging.  Is there a way to turn on debugging either client or server side to see what is being sent in the request and what is being sent back?  I am able to access the remote database using the command-line "mongo" client so I don't think this is anything related to networking.  In fact, when I run my Grails app, I can see that it makes a connection with the mongod server.  The command line request also returns the record whereas Grails waits and then times out.
>
> Person.groovy
>
> String person_id;
> String name;
>
> def res = Person.findByPerson_id("x-123-456-xyz");
>
> Ideas?
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MongoDB GORM connects with server but times out

Robert La Ferla-2
I found out the root cause of my problem but I don't have a solution yet.  GORM expects the "_id" field to be a NumberLong whereas MongoDB defaults it to a bson ObjectId.  It doesn't seem to care whether or not there is a "version" field but then again I didn't try writing anything yet.

Grails/GORM likes this:

MongoDB shell version: 2.0.2> person = { "_id": NumberLong(1), first: "John", last: "Smith"};
{ "_id" : NumberLong(1), "first" : "John", "last" : "Smith" }
> db.people.save(person);
> db.people.find()
{ "_id" : NumberLong(1), "first" : "John", "last" : "Smith" }

but doesn't like this:

> person = {first: "John", last: "Smith"};
{ "first" : "John", "last" : "Smith" }
> db.people.save(person);
> db.people.find()
{ "_id" : ObjectId("4f4d8f33c734eb70cea597e5"), "first" : "John", "last" : "Smith" }

Is there anyway around this or am I forced to change the _id property in the database to be a NumberLong ?

Thanks again.


On Feb 28, 2012, at 7:47 PM, Robert La Ferla wrote:

> My primary key is a string and not a number.  Could that be the issue?  I can't find many source code examples out there on this.  If you are using Mongo and Grails, I'd like to know if you are able to have records where the primary identifier is a string.
>
> Also, I turned on verbose logging on the mongod server (-vv) and it did show the query.  I'm stumped for now.  I am using Grails 2.0.1 and MongoDB GORM 1.0.0.RC4.  Maybe I should try another version or perhaps the Morphia one?
>
> Thanks in advance!
>
> On Feb 28, 2012, at 7:31 PM, Robert La Ferla wrote:
>
>> I am trying to do a simple query against a remote MongoDB database and it is hanging.  Is there a way to turn on debugging either client or server side to see what is being sent in the request and what is being sent back?  I am able to access the remote database using the command-line "mongo" client so I don't think this is anything related to networking.  In fact, when I run my Grails app, I can see that it makes a connection with the mongod server.  The command line request also returns the record whereas Grails waits and then times out.
>>
>> Person.groovy
>>
>> String person_id;
>> String name;
>>
>> def res = Person.findByPerson_id("x-123-456-xyz");
>>
>> Ideas?
>>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MongoDB GORM connects with server but times out

Graeme Rocher
Administrator
As per the documentation, you need to change the id to a String or
ObjectId type (the latter recommended). Just specify:

ObjectId id

In your class

Cheers

On Wed, Feb 29, 2012 at 3:39 AM, Robert La Ferla
<[hidden email]> wrote:

> I found out the root cause of my problem but I don't have a solution yet.  GORM expects the "_id" field to be a NumberLong whereas MongoDB defaults it to a bson ObjectId.  It doesn't seem to care whether or not there is a "version" field but then again I didn't try writing anything yet.
>
> Grails/GORM likes this:
>
> MongoDB shell version: 2.0.2> person = { "_id": NumberLong(1), first: "John", last: "Smith"};
> { "_id" : NumberLong(1), "first" : "John", "last" : "Smith" }
>> db.people.save(person);
>> db.people.find()
> { "_id" : NumberLong(1), "first" : "John", "last" : "Smith" }
>
> but doesn't like this:
>
>> person = {first: "John", last: "Smith"};
> { "first" : "John", "last" : "Smith" }
>> db.people.save(person);
>> db.people.find()
> { "_id" : ObjectId("4f4d8f33c734eb70cea597e5"), "first" : "John", "last" : "Smith" }
>
> Is there anyway around this or am I forced to change the _id property in the database to be a NumberLong ?
>
> Thanks again.
>
>
> On Feb 28, 2012, at 7:47 PM, Robert La Ferla wrote:
>
>> My primary key is a string and not a number.  Could that be the issue?  I can't find many source code examples out there on this.  If you are using Mongo and Grails, I'd like to know if you are able to have records where the primary identifier is a string.
>>
>> Also, I turned on verbose logging on the mongod server (-vv) and it did show the query.  I'm stumped for now.  I am using Grails 2.0.1 and MongoDB GORM 1.0.0.RC4.  Maybe I should try another version or perhaps the Morphia one?
>>
>> Thanks in advance!
>>
>> On Feb 28, 2012, at 7:31 PM, Robert La Ferla wrote:
>>
>>> I am trying to do a simple query against a remote MongoDB database and it is hanging.  Is there a way to turn on debugging either client or server side to see what is being sent in the request and what is being sent back?  I am able to access the remote database using the command-line "mongo" client so I don't think this is anything related to networking.  In fact, when I run my Grails app, I can see that it makes a connection with the mongod server.  The command line request also returns the record whereas Grails waits and then times out.
>>>
>>> Person.groovy
>>>
>>> String person_id;
>>> String name;
>>>
>>> def res = Person.findByPerson_id("x-123-456-xyz");
>>>
>>> Ideas?
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MongoDB GORM connects with server but times out

Robert La Ferla-2
Thank you.  That worked.  

Best,
Robert

On Feb 29, 2012, at 3:01 AM, Graeme Rocher wrote:

> As per the documentation, you need to change the id to a String or
> ObjectId type (the latter recommended). Just specify:
>
> ObjectId id
>
> In your class
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...