Querying for an element of an embedded array
flag
Messages 41 - 50 of 155 - Collapse all
/groups/adfetch?adid=2PlFAA8AAADU0BMYrLxk_40bNCvOgwh0
Querying for an element of an embedded array - Email updates to me  
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
 
1.  gutzeit  
View profile   Translate to Translated (View Original)
 More options Feb 5 2011, 2:50 am
From: gutzeit <gutz...@gmail.com>
Date: Fri, 4 Feb 2011 23:50:21 -0800 (PST)
Local: Sat, Feb 5 2011 2:50 am
Subject: Querying for an element of an embedded array

Hi,

I have an Entity with a List of @Embedded objects.

@Entity
class Entity
    @Embedded
    List<SomethingEmbedded> elements

class SomethingEmbedded
     String name;
     String id;

How can I query to get an element in the embedded array by, lets say id
attribute.
I want the query to return only "SomethingEmbedded", without the "Parent"
Entity object, since the "elements" can have thousands of elements and I do
not need all the parent object, only on element on elements list.

Is it possible with Morphia/Mongo ?

Thanks in advance for your help.


 
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.
2.  Scott Hernandez  
View profile  
 More options Feb 5 2011, 3:12 am
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sat, 5 Feb 2011 00:12:42 -0800
Local: Sat, Feb 5 2011 3:12 am
Subject: Re: [morphia] Querying for an element of an embedded array
It is not possible with mongo. When it is, morphia can add support for it.

You may want to follow these issues:
http://jira.mongodb.org/browse/SERVER-828
http://jira.mongodb.org/browse/SERVER-1264
http://jira.mongodb.org/browse/SERVER-142


 
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.
3.  gutzeit  
View profile   Translate to Translated (View Original)
 More options Feb 5 2011, 6:45 am
From: gutzeit <gutz...@gmail.com>
Date: Sat, 5 Feb 2011 03:45:18 -0800 (PST)
Local: Sat, Feb 5 2011 6:45 am
Subject: Re: [morphia] Querying for an element of an embedded array

Understood.

In you opinion is this something I should take into account when designing
my datamodel ? For example making the arrays that I expect to grow as
entities rather than embedded objects ?

Thanks in advance.


 
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.
4.  gutzeit  
View profile  
 More options Feb 5 2011, 7:16 am
From: gutzeit <gutz...@gmail.com>
Date: Sat, 5 Feb 2011 04:16:54 -0800 (PST)
Local: Sat, Feb 5 2011 7:16 am
Subject: Re: [morphia] Querying for an element of an embedded array

As an alternative is there a way to return the parent object with the
embedded array with only one element, the one I was searching for ? Lack of
support of this kind of queries kinda makes embedding of large arrays a
total no-go.


 
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.
5.  Scott Hernandez  
View profile  
 More options Feb 5 2011, 10:51 am
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sat, 5 Feb 2011 07:51:05 -0800
Local: Sat, Feb 5 2011 10:51 am
Subject: Re: [morphia] Querying for an element of an embedded array
That is exactly what the first issue describes in the list. There are
many limitations using embedded arrays (and deeply nested objects)
which you may want to consider.

Storing constantly growing entities can have a large performance
penalty in terms of IO because of the way in-place updates work. Each
time you grow an entity it must first try to update the existing
document in-place, but in the case where the new one is too big to fit
in the allocated space, then it must move it to a new location (while
padding the size of the new allocation for future growth) and update
all the indexes pointing to it. If you do this a lot it could increase
the IO costs for each write operation; the result of this may be that
more write-heavy users should steer away from this pattern if the read
frequency isn't enough to justify the additional write costs.


 
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.
$elemMatch Query questions - Email updates to me  
1.  Brian KimJohnson  
View profile  
 More options Feb 6 2011, 12:45 am
From: Brian KimJohnson <briankimjohn...@gmail.com>
Date: Sat, 5 Feb 2011 21:45:59 -0800 (PST)
Local: Sun, Feb 6 2011 12:45 am
Subject: $elemMatch Query questions
Greetings all,

Using Morphia on a project and it has been great thus far so thanks
for all the work!

I am having trouble making this query in Morphia.  Can some tell me
how to run a complex $elemMatch

db.BaseActivity.find(
{ "_id" : ObjectId("4d4a19cc93fb69115e88e82c") ,
         "rs" : { "$elemMatch"  :
                    { "_id" : ObjectId("4d4a1d0fdda16911f16ac0ac") ,
                     "l" : { "$nin" : [ 127]}}
         }

})

Notice that for this query I am specifying an array of embedded object
"rs".  In order to select an object from the array I am searching for
an id and making sure that the array "l" does not contain 127.

Can this query be done using Morphia?  I know how to generate it with
only the _id filter but how can I do both?

*Sample query for only one attribute:
Query updateQuery = ds.createQuery(parent.getClass()).filter("_id",
parent.getId());

Thanks!


 
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.
2.  Scott Hernandez  
View profile  
 More options Feb 6 2011, 2:04 am
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sat, 5 Feb 2011 23:04:31 -0800
Local: Sun, Feb 6 2011 2:04 am
Subject: Re: [morphia] $elemMatch Query questions
On Sat, Feb 5, 2011 at 9:45 PM, Brian KimJohnson

There is not an easy way to express that query with the query
interface. You will need to create a DBObject for the filter.

updateQuery.filter("rs elem", BasicDBObjectBuilder.start("_id",
objId).push("I").add("$nin",
Collections.singletonList(127)).pop().get());

(it is something like that; I haven't tested that.)


 
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.
3.  Brian KimJohnson  
View profile  
 More options Feb 7 2011, 3:37 pm
From: Brian KimJohnson <briankimjohn...@gmail.com>
Date: Mon, 7 Feb 2011 12:37:50 -0800 (PST)
Local: Mon, Feb 7 2011 3:37 pm
Subject: Re: $elemMatch Query questions
That worked perfectly.  Thanks Scott!

On Feb 6, 2:04 am, Scott Hernandez <scotthernan...@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.
Query By Example - Email updates to me  
1.  gutzeit  
View profile  
 More options Feb 6 2011, 4:32 pm
From: gutzeit <gutz...@gmail.com>
Date: Sun, 6 Feb 2011 13:32:02 -0800 (PST)
Local: Sun, Feb 6 2011 4:32 pm
Subject: Query By Example

Hi,

Is there a way to execute query by example using Morphia?

Something like:

User exampleUser = new User("em...@ddd.com");
User realUser = ds.createQuery(User.class).filter("this",
exampleEntity).get();


 
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.
2.  Scott Hernandez  
View profile  
 More options Feb 6 2011, 5:20 pm
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Sun, 6 Feb 2011 14:20:15 -0800
Local: Sun, Feb 6 2011 5:20 pm
Subject: Re: [morphia] Query By Example
No, but I can add it to the list. You can do this with embedded
objects, just not the root entity.

I'm thinking something like:

ds.QBE(exampleUser).get/asList()

Is QBE a good method name, or maybe "queryByExample"?


 
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.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2013 Google