Problem In Query

16 views
Skip to first unread message

Ali Akhtar

unread,
Feb 9, 2014, 12:36:39 AM2/9/14
to mongoo...@googlegroups.com
Schema Name Show:

[ { Name: 'ali',
    __v: 0,
    _id: 52f5ff53b892663c0f000001,
    Comment: 
     [ { second1: 'Comment2', text: 'comment1' },
       { second1: 'contentde', text: 'de' },
       { second1: 'contentde', text: 'de' } ] } ]

 Show.find(
        {
            Comment: {
                text: "comment1"
            }
        },function(err,doc){
            console.log(doc);
        })


Problem:
i want to get this in return :

 'comment1'

Thankx in Advance.

Joe Wagner

unread,
Feb 9, 2014, 1:21:10 AM2/9/14
to mongoo...@googlegroups.com
The $elemMatch operator might help.  Something like 
Show.find({Comment:{$elemMatch: {text:'comment1'}}}, function (err,docs) { console.log(docs); });
hope that helps,
-Joe
Message has been deleted

Ali Akhtar

unread,
Feb 9, 2014, 1:39:55 AM2/9/14
to mongoo...@googlegroups.com
Console Output:

[ { Name: 'ali',
    __v: 0,
    _id: 52f5ff53b892663c0f000001,
    Comment: 
     [ { second1: 'Comment2', text: 'comment1' },
       { second1: 'contentde', text: 'de' },
       { second1: 'contentde', text: 'de' } ] } ]

It gave me whole .
I want only "Comment2" in return. or  .this object.

Ali Akhtar

unread,
Feb 9, 2014, 2:07:57 AM2/9/14
to mongoo...@googlegroups.com
Its works
Thankx for ur help..
Reply all
Reply to author
Forward
0 new messages