Bug specifying the $gt operator in embedded documents

20 views
Skip to first unread message

RameshVel

unread,
Sep 7, 2010, 4:49:32 AM9/7/10
to mongodb-user
Hi All,
$gt operator fetches the records whose value is greater than **or
equal** to the given value while querying embedded documents. But this
fetches the greater than values only in normal documents.

Sample code:

db.Blog.find( { "comments.rating" : { $gt : 3 } } ) - result including
the comments ratings 3
db.emp.find( { "age": {$gt:25} }) - results are docs with age above 25

can someone look into that..

Cheeers
Ramesh Vel

RameshVel

unread,
Sep 7, 2010, 4:43:18 AM9/7/10
to mongodb-user

Kyle Banker

unread,
Sep 7, 2010, 7:33:41 AM9/7/10
to mongod...@googlegroups.com
Can you provide a sample document that allows us to reproduce this? Can't reproduce from what you've given.


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


nipra

unread,
Sep 7, 2010, 8:20:15 AM9/7/10
to mongodb-user
Hi,

On Sep 7, 1:49 pm, RameshVel <ramesh...@gmail.com> wrote:
> Hi All,
>      $gt operator fetches the records whose value is greater than **or
> equal** to the given value while querying embedded documents. But this
> fetches the greater than values only in normal documents.

I thinks it's $gte for greater than or equal to.

Regards,
nipra

RameshVel

unread,
Sep 8, 2010, 2:55:35 AM9/8/10
to mongodb-user
Hi Kyle,
below the query and returned result document.

Embedded doc:

> db.Blog.find( { "comments.rating" : { $gt : 3 } } )
{ "_id" : ObjectId("a86ef30159a5bbc839000000"), "Author" : "Ram",
"Header" : "My
First Mongo test", "body" : "test content", "comments" : [
{
"_id" : null,
"Author" : "J",
"body" : "Its good",
"rating" : 4
},
{
"_id" : null,
"Author" : "R",
"body" : "Its ok",
"rating" : 3
},
{
"_id" : null,
"Author" : "A",
"body" : "bad",
"rating" : 0
}
] }
{ "_id" : ObjectId("65580f0259a5bb7c34000000"), "Author" : "Ram-1",
"Header" : "
My First Mongo test", "body" : "test content", "comments" : [
{
"_id" : null,
"Author" : "J_1",
"body" : "Its good",
"rating" : 4
},
{
"_id" : null,
"Author" : "R",
"body" : "Its ok",
"rating" : 3
},
{
"_id" : null,
"Author" : "A",
"body" : "bad",
"rating" : 0
}
] }
{ "_id" : ObjectId("9fa9100259a5bbb42a000000"), "Author" : "Jay",
"Header" : "My
First Mongo test", "body" : "test content", "comments" : [
{
"_id" : null,
"Author" : "asd",
"body" : "Its good",
"rating" : 4
},
{
"_id" : null,
"Author" : "sdfsd",
"body" : "Its ok",
"rating" : 3
},
{
"_id" : null,
"Author" : "sdfsd",
"body" : "bad",
"rating" : 0
}
] }
{ "_id" : ObjectId("88e1100259a5bbb42a010000"), "Author" : "Kiran",
"Header" : "
My First Mongo test", "body" : "test content", "comments" : [
{
"_id" : null,
"Author" : "asd",
"body" : "Its good",
"rating" : 4
},
{
"_id" : null,
"Author" : "sdfsd",
"body" : "Its ok",
"rating" : 3
},
{
"_id" : null,
"Author" : "sdfsd",
"body" : "bad",
"rating" : 0
}
] }

Ha i found one more interesting thing
when i run this query

> db.Blog.find( { "comments.rating" : { $gt : 4 } } )

it wasn't return any results. because i don't have documents above
rating 4. Seems { $gt : 4 } is working fine here.

Why { $gt : 3 } is shows wrong result..

Cheers

On Sep 7, 4:33 pm, Kyle Banker <k...@10gen.com> wrote:
> Can you provide a sample document that allows us to reproduce this? Can't
> reproduce from what you've given.
>
> On Tue, Sep 7, 2010 at 4:43 AM, RameshVel <ramesh...@gmail.com> wrote:
> > Hi All,
> >     $gt operator fetches the records whose value is greater than **or
> > equal** to the given value while querying embedded documents. But this
> > fetches the greater than values only in normal documents.
>
> > Sample code:
>
> > db.Blog.find( { "comments.rating" : { $gt : 3 } } ) - result including
> > the comments ratings 3
> > db.emp.find( { "age": {$gt:25} }) - results are docs with age above 25
>
> > can someone look into that..
>
> > Cheeers
> > Ramesh Vel
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsu...@googlegroups.com>
> > .

RameshVel

unread,
Sep 8, 2010, 2:56:48 AM9/8/10
to mongodb-user
Yeah i know that... but i don't know why $gt works this way in some
documents.

Cheers

Eliot Horowitz

unread,
Sep 8, 2010, 8:07:10 AM9/8/10
to mongod...@googlegroups.com
When using $gt with embedded, it finds a document where there exists a match. In all of those docs there is a 4, so it matches.

> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.

RameshVel

unread,
Sep 8, 2010, 8:19:31 AM9/8/10
to mongodb-user
thanks Eliot, i understand now....

On Sep 8, 5:07 pm, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> When using $gt with embedded, it finds a document where there exists a match. In all of those docs there is a 4,  so it matches.
>
Reply all
Reply to author
Forward
0 new messages