Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Mongo Id
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
FabioEbner  
View profile  
 More options May 19 2012, 11:25 am
From: FabioEbner <fabioeb...@gmail.com>
Date: Sat, 19 May 2012 08:25:19 -0700 (PDT)
Local: Sat, May 19 2012 11:25 am
Subject: Mongo Id

Hi, i create one class with morphia.. and put one ObejctID, but i wanna
know if i have another ID , something like SGDB id, sequential id, because
i need to pass the id to view and than back to front. so i can olny pass
the id

tks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Hernandez  
View profile  
 More options May 19 2012, 11:39 am
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sat, 19 May 2012 11:39:22 -0400
Local: Sat, May 19 2012 11:39 am
Subject: Re: [mongodb-user] Mongo Id
You can use any id generation system you want. By default an ObjectID
is suggested since it doesn't require any interaction with the server
to generate and is unique.

You can simply pass the (hex) string version of the ObjectId as the id
to your html/web-app; that works just fine.

If you want to maintain a sequence/counter there are example in the
docs and an example annotation in morphia you can use. It is not
suggested as it requires going to the server before every insert to
get an id.
http://www.mongodb.org/display/DOCS/How+to+Make+an+Auto+Incrementing+...
http://code.google.com/p/morphia/source/browse/trunk/morphia/src/main...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fabio Ebner  
View profile  
 More options May 19 2012, 2:27 pm
From: Fabio Ebner <fabioeb...@gmail.com>
Date: Sat, 19 May 2012 15:27:44 -0300
Local: Sat, May 19 2012 2:27 pm
Subject: Re: [mongodb-user] Mongo Id

can you send one example? i use ObjectID to create automatic the id.

2012/5/19 Scott Hernandez <scotthernan...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Hernandez  
View profile  
 More options May 19 2012, 4:14 pm
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sat, 19 May 2012 16:14:59 -0400
Local: Sat, May 19 2012 4:14 pm
Subject: Re: [mongodb-user] Mongo Id
An example of what?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fabio Ebner  
View profile  
 More options May 19 2012, 4:20 pm
From: Fabio Ebner <fabioeb...@gmail.com>
Date: Sat, 19 May 2012 17:20:51 -0300
Local: Sat, May 19 2012 4:20 pm
Subject: Re: [mongodb-user] Mongo Id

how i got from db

2012/5/19 Scott Hernandez <scotthernan...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giovanni Fabio  
View profile  
 More options May 19 2012, 4:37 pm
From: Giovanni Fabio <assisten...@gmail.com>
Date: Sat, 19 May 2012 22:37:21 +0200
Local: Sat, May 19 2012 4:37 pm
Subject: Re: [mongodb-user] Mongo Id

SELECT * FROM tablemane WHERE (a=1 OR b=1) AND (a=2 OR b=2)

examples of mongodb query
in mongodb ???

2012/5/19 Scott Hernandez <scotthernan...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fabio Ebner  
View profile  
 More options May 19 2012, 4:41 pm
From: Fabio Ebner <fabioeb...@gmail.com>
Date: Sat, 19 May 2012 17:41:23 -0300
Local: Sat, May 19 2012 4:41 pm
Subject: Re: [mongodb-user] Mongo Id

no..how i use java + morphia to get one data with id.. because i use java +
morphi

and my entity i create just like this.

@id
private ObjectId cdProduct;

2012/5/19 Giovanni Fabio <assisten...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Hernandez  
View profile  
 More options May 19 2012, 5:34 pm
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sat, 19 May 2012 17:34:10 -0400
Local: Sat, May 19 2012 5:34 pm
Subject: Re: [mongodb-user] Mongo Id
Datastore ds = ...

instance = ds.get( MyClass.class, id );

http://code.google.com/p/morphia/wiki/Datastore#Get_Methods


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fabio Ebner  
View profile  
 More options May 20 2012, 6:18 pm
From: Fabio Ebner <fabioeb...@gmail.com>
Date: Sun, 20 May 2012 19:18:04 -0300
Local: Sun, May 20 2012 6:18 pm
Subject: Re: [mongodb-user] Mongo Id

Yes, but my id is an ObjectID and this ObjectID have a few properties, so
in that way i need to pass the complete ObjectID?
i want something i just pass one number, not one object

did you undestand
2012/5/19 Scott Hernandez <scotthernan...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Hernandez  
View profile  
 More options May 20 2012, 6:44 pm
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sun, 20 May 2012 18:44:05 -0400
Local: Sun, May 20 2012 6:44 pm
Subject: Re: [mongodb-user] Mongo Id
If you want to use something other than an ObjectId you can.

See my first response if you want to use morphia with a
auto-incrementing number.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ravi  
View profile  
 More options Jul 20 2012, 6:20 am
From: ravi <ravikapoor...@gmail.com>
Date: Fri, 20 Jul 2012 03:20:23 -0700 (PDT)
Local: Fri, Jul 20 2012 6:20 am
Subject: Re: [mongodb-user] Mongo Id

I am running into the same problem. Let me try to explain
I want the unique id to be string, so I can save in browser cookie and
retrieve the object when the user comes back.
I would rather not use my own unique Id generation as I am not an expert
and can possibly generate duplicates, thus messing up the system.
If I use ObjectId as recommended, it creates a complex structure that I do
not know how to store in the browser.
I used ObjectId.getStringMongod() to convert it to a string value to store
in cookie, however now I could not figure out a way to retrieve the object
using this string value.

Hope that clarifies the issue.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Millman  
View profile  
 More options Jul 20 2012, 10:07 am
From: Sam Millman <sam.mill...@gmail.com>
Date: Fri, 20 Jul 2012 15:07:45 +0100
Local: Fri, Jul 20 2012 10:07 am
Subject: Re: [mongodb-user] Mongo Id

"If I use ObjectId as recommended, it creates a complex structure that I do
not know how to store in the browser."

Complex structure? It's a string, you make the cookie contents equal the
string.

"I used ObjectId.getStringMongod() to convert it to a string value to store
in cookie, however now I could not figure out a way to retrieve the object
using this string value."

You must recast it as an ObjectId using the string as the constructor param.

On 20 July 2012 11:20, ravi <ravikapoor...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ravi  
View profile  
 More options Jul 20 2012, 2:30 pm
From: ravi <ravikapoor...@gmail.com>
Date: Fri, 20 Jul 2012 11:30:09 -0700 (PDT)
Local: Fri, Jul 20 2012 2:30 pm
Subject: Re: [mongodb-user] Mongo Id

Thanks for helping Sammaye, I am still unable to retrieve the object. Here
is my situation:

1. ObjectId when converted to JSON results in
- {"time":1342807473000,"new":false,"machine":-1045725356,"timeSecond":134280 7473,"inc":-208935720}
I am not sure why it converts simple string to complex structure, but
somehow it does. Though is not relevant anymore. I am getting string value
using id.toStringMongod()

2. I tried all the following method to retrieve the object back. ALL of
them fail. I cant seem to get the syntax right. Help please.

user1 = ds.find(User.class).field("id").equal(new ObjectId(id)).get()
user1 = ds.find(User.class).field("id").equal(id).get()

query = ds.find(User.class).filter("id", id);
user1 = query.get();

query = ds.find(User.class).filter("id", new ObjectId(id));
user1 = query.get();

query = ds.find(User.class);
query.put("id", new ObjectId(id))
user1 = query.get();

query = ds.find(User.class);
query.put("_id", new ObjectId(id))
user1 = query.get();

query = ds.find(User.class).filter("id", "ObjectId(\"" + id + "\")" );
user1 = query.get();

query = ds.find(User.class).filter("_id", "ObjectId(\"" + id + "\")" );
user1 = query.get();
user1 = ds.get(User.class, new ObjectId(id));

All of them print user = null. :(
thanks

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ravi  
View profile  
 More options Jul 20 2012, 3:51 pm
From: ravi <ravikapoor...@gmail.com>
Date: Fri, 20 Jul 2012 12:51:00 -0700 (PDT)
Subject: Re: [mongodb-user] Mongo Id

Wow, finally figured it out after hours of work. Here is the code for other
newbies out there
-----------------------------------
@Entity("users")
public class User {
@Id ObjectId id;

}

-----------------------------------
Mongo mongo = new Mongo();
Morphia morphia = new Morphia();
morphia.map(User.class);
Datastore ds = morphia.createDatastore(mongo, "abcd");
// saving a user
 User user = new User();
 user.name = "idiot";
 user.save()
// get id for future as follows
String userId = user.id.toStringMongod()
// now retrieve the same user back from DB
Query q1 = ds.createQuery(User.class).field("id").equal(new
ObjectId(userId));
User user1 = q1.get();

-----------------------------------
Hope that helps somebody out there on the internets

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »