1

I am using mongoDB and Codeigniter PHP framework in my project. i am dealing with an E-commerce website. i am using mongoDB to store product features and images of the products. product details are stored in a collection and their images are stored in GridFS bucket with the product code. i want to return a product details and images by passing the product code to DB. i wrote two queries, one for retrieving the product details from the collection one for the images of the product from the GridFS.

The two query results are allocated to two arrays.so iam not able to combine the result and make it as a single araay to pass that into my view page.

I am bugged up with this. please help..

profesor79
  • 9,213
  • 3
  • 31
  • 52
Telen Stanley
  • 310
  • 1
  • 6
  • 16
  • 2
    You would loop through the product array and for each loop iteration search/loop through the image array and assign the images to the current product item. If you post examples of both arrays we can help you better. – cyberwombat Sep 13 '16 at 03:16
  • Please clearify the question, include some sample documents – HoefMeistert Sep 13 '16 at 12:46
  • thank you for the feedback. I really wanted to know something about retrieving images from GridFS. by converting the mongoclient object into base64 format and passing it to the html image tag. is that a good method to display images from gridfs ? – Telen Stanley Sep 13 '16 at 15:42
  • @TelenStanley i Would not advise it. My guess is you want to load the images fast and cache then where possible. Loading each image from gridfs is not effective. When possible look into Hosting your images elsewhere, there are very good and fast alternatives available. For example you could look at http://cloudinary.com – HoefMeistert Sep 13 '16 at 15:54

1 Answers1

0

I dont have experience in php, but imho, this question mixes apples with bananas.

GridFs storage is using a bit different serialisation as it can cover documents over 16MB limit (the chunk size is about 255kB) and that is reflected in driver interface. Mongo single document can be up to 16MB, so as far as images after serialisation are fitting in BSON limit, then using standard collection will could act as a solution.

profesor79
  • 9,213
  • 3
  • 31
  • 52