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>
> > .