-1

When I query from collection in MongoDB and it has results:

[ { details: 
     [ { owner: '57f52829bcc705bb1c37d611',
         nameprd: 'fsfsdaf',
         price: 15000000,
         descrice: 'sfsdfsdaf',
         number: 4,
         dateOff: '2016-06-12T17:00:00.000Z',
         _csrf: 'CPlxeLpq-vYfTTWTgSpR6bsyapbDVgDCKzTc',
         image: 'samsung-galaxy-note-7.png',
         createdAt: '2016-10-06T16:43:11.109Z',
         updatedAt: '2016-10-06T16:43:13.061Z',
         id: '57f67f1f7ab99e5824652208' } ],
    name: 'Máy tính bảng',
    _csrf: 'Ze6OhtgL-2hZvG7TuP9NO4fjY90rA7x46bWA',
    createdAt: '2016-10-05T16:19:53.331Z',
    updatedAt: '2016-10-06T16:43:13.021Z',
    id: '57f52829bcc705bb1c37d611' },
  ]

Now, how to get value which called details in this result.

Thanks.

4J41
  • 5,005
  • 1
  • 29
  • 41
  • 1
    Please show the code that queried the database. – E_net4 Oct 06 '16 at 17:57
  • If there are multiple objects in that array, you need to loop through it. If there is a single result that you expect `every` time - you can use .find in mongoose. It will return the object which you can access directly - `result.details[0].owner; result.name; result.id` – nirvair Oct 07 '16 at 13:39

1 Answers1

0

You should add the query the following syntax: ,{'details':1}

For example:

If that is the original query:

db.person.find({'name':'joe'})

Than the following query returns only the details value of the query:

db.person.find({'name':'joe'},{'details':1})

The addition of the ,{'details':1} means that you want to get only the data for the details. It is uses as a filter to the extensive query.

Rotem
  • 1,381
  • 1
  • 11
  • 23