2

I have below type of collection in mongodb:

Array
(
[_id] => 4fcf383a5990581c0b000015
[user_id] => 1
[username] => admin
[password] => 21232f297a57a5a743894a0e4a801fc3
[first_name] => admin
[last_name] => admin
[address] => 
[address_2] => 
 [deshboard_report] => Array
    (
        [0] => Array
            (
                [report_ids] => 1
                [rpt_color] => color-red
                [rpt_status] => max
                [report_title] => Last Point
                [report_file] => last_location
            )
        [1] => Array
            (
                [report_ids] => 2
                [rpt_color] => color-green
                [rpt_status] => max
                [report_title] => Inactive Device
                [report_file] => inactive_devices
            )
    )
)

I want to search in report_ids and that search return sub array of deshboard_report how it is possible?

I use this library to connect: https://github.com/alexbilbie/codeigniter-mongodb-library

1

1 Answer 1

1

When querying for an element in an array, your results will currently return the whole document by default.

You can return whole documents matching subarrays with specific report_ids using $elemMatch.

Example for the JS shell .. find documents with report_ids=2 :

  db.collection.find({'deshboard_report': {"$elemMatch": {report_ids: 2}}});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.