Announcement Announcement Module
Collapse
No announcement yet.
Spring Data MongoDB: Querying for size of an array of embedded documents Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data MongoDB: Querying for size of an array of embedded documents

    Hello,

    Using Spring Data MongoDB version : 1.0.2.RELEASE and Spring Data Framework : 3.1.1.RELEASE
    I am trying to query for size of an array of embedded documents. I basically have a tree structure with references to parents and children documents.

    an example document would be:

    Code:
    { "_id" : ObjectId("50099513b760e35d421bab44"), "_class" : "com.example.ExampleClass", "name" : "test1", "parents" : [ ], "children" : [ 	{
    		"$ref" : "ExampleClass",
    		"$id" : ObjectId("50099516b760e35d421bab45")
    	}, 	{
    		"$ref" : "ExampleClass",
    		"$id" : ObjectId("50099516b760e35d421bab47")
    	} ] }
    I am trying to do the following query
    Code:
    db.coll.find({parents : {$size : 0}})
    using the @Query annotation.

    Here is my actual custom query in my repository interface

    Code:
    @Query(" { parents : { $size : 0 } }")
    List<ExampleClass> getAllTopLevelComponents();
    However for no apparent reason, the thread terminates without any exception being thrown.

    Anyone have any ideas what might be causing this ?

    Thanks,
    Deep
    Last edited by deepdmistry; Jul 20th, 2012, 02:09 PM.

  • #2
    @Query annotation with embedded documents

    Update:

    I realized that none of my @Query methods work with embedded documents. Any pointers on this would be appreciated.

    Thank You,
    Deep


    Originally posted by deepdmistry View Post
    Hello,

    I am trying to query for size of an array of embedded documents. I basically have a tree structure with references to parents and children documents.

    an example document would be:

    Code:
    { "_id" : ObjectId("50099513b760e35d421bab44"), "_class" : "com.example.ExampleClass", "name" : "test1", "parents" : [ ], "children" : [ 	{
    		"$ref" : "ExampleClass",
    		"$id" : ObjectId("50099516b760e35d421bab45")
    	}, 	{
    		"$ref" : "ExampleClass",
    		"$id" : ObjectId("50099516b760e35d421bab47")
    	} ] }
    I am trying to do the following query
    Code:
    db.coll.find({parents : {$size : 0}})
    using the @Query annotation.

    Here is my actual custom query in my repository interface

    Code:
    @Query(" { parents : { $size : 0 } }")
    List<ExampleClass> getAllTopLevelComponents();
    However for no apparent reason, the thread terminates without any exception being thrown.

    Anyone have any ideas what might be causing this ?

    Thanks,
    Deep

    Comment

    Working...
    X