Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:40:27+00:00 2026-06-11T11:40:27+00:00

I have a model that looks like this: class Pdf extends \lithium\data\Model { protected

  • 0

I have a model that looks like this:

class Pdf extends \lithium\data\Model
{

    protected $_meta = array('source' => 'fs.files');
    protected $_schema = array('_id'=>array('type'=>'id'));

    public $file;

    /**
    * @param $zipfile string The full name and path of a zip file
    * @param $filename string
    */
    public static function loadFromFile($zipfile, $filename){
        $name = 'zip://'.$zipfile.'#'.$filename;
        $pdf = Pdf::create(); 
        $pdf->file = file_get_contents($name);
        $pdf->filename = $filename;
        $pdf->metadata = ["filename" => $filename, "zipfile" => $zipfile];
        return $pdf;
    }
}

The static function takes the full name of a zip archive and the name of a file in the archive, creates a model, loads content from the archived file, sets some metadata, and returns the model. This is used in a console command I’m writing that will iterate through a list of zip files, each containing a bunch of pdfs, and add the pdfs to the database.

When I save the model, the pdf does indeed get added to the database. I can view all the pdfs from the MongoDB console, i.e. with db.fs.files.find(). I can also get a pdf from the database using the mongofiles command.

However, it would really be nice if instead of storing the pdfs under fs.files I could store them under fs.files.pdfs. This is because I’m planning on also storing jpegs and text documents in the same database.

If I change $_meta in the class to array('source' => 'fs.files.pdfs'), my console command seems to output the pdf document to the terminal instead of adding it (offhand, I’d like to know why Lithium is doing that!)

I’ve checked the documentation and haven’t been able to figure out what I’m doing wrong. Is there any way to get Lithium to store my files in separate collections depending on the model being used?

(My apologies if my terminology is inaccurate; this is my first attempt to use Lithium and MongoDB beyond the basic tutorials.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:40:28+00:00Added an answer on June 11, 2026 at 11:40 am

    However, it would really be nice if instead of storing the pdfs under fs.files I could store them under fs.files.pdfs. This is because I’m planning on also storing jpegs and text documents in the same database.

    At the moment, you can’t name your source fs.files.pdfs, but pdfs.files and photos.files …

    I’ve checked the documentation and haven’t been able to figure out what I’m doing wrong. Is there any way to get Lithium to store my files in separate collections depending on the model being used?

    Take a look to the highlighted lines here: https://github.com/UnionOfRAD/lithium/blob/master/data/source/MongoDb.php#L387-390

    Here is how Lithium handles that

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a source model that looks like this: public class FooBar { public
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a view model that looks like this public class ViewModelRound2 { public
I have a model that looks something like this: public abstract class Parent {
I have a class in my domain model root that looks like this: namespace
I have Django model that looks like this: class Categories(models.Model): Model for storing the
In my application I have a model that looks like this: class Talk(models.Model): title
I have a TakeAction model that looks like this: class TakeAction < ActiveRecord::Base belongs_to
I have a view model that looks like this: public class VenueIndexViewModel : BaseViewModel
I have a model that looks like this: class ProjectImage(models.Model): big_thumb = ThumbnailField(upload_to='profiles', size=(500,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.