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

  • Home
  • SEARCH
  • 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 8322859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:31:34+00:00 2026-06-08T23:31:34+00:00

Im trying to store a document in a different collection by using Mongodb and

  • 0

Im trying to store a document in a different collection by using Mongodb and symfony2

This is my controller who sets the document into the db.

public function createAction(){
$post = new Post();
$post->setUrl('A Foo Bar');
$post->setTitle('asdf');
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$dm->persist($post);
$dm->flush();
return new Response('Created post id '.$post->getId());}

As you can see, this is the example for the official documentation on DoctrineMongoDBBundle

But the problem is that by default it creates the document into a Collection named as the class, in my case is Post(), so the collection name is Post. I will like to save the document into a Collection named for example charlies_posts or any string as a variable.

  • 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-08T23:31:36+00:00Added an answer on June 8, 2026 at 11:31 pm

    It’s easy 🙂 In the definition of your document class just use the “collection” parameter.

    Here is an exemple :

    <?php
    
    namespace MyProject\Document;
    
    use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
    
    /**
     * @ODM\Document(
     *     collection="charlies_posts"
     * )
     */
    class Post
    {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to store an image into an SQL database without using temporary files.
I'm trying to retrieve a document stored in MongoDB using its _id of the
I'm trying to store a document in SQL Server 2008 using the Entity Framework.
Im trying to store a list,collection of data objects in Hbase. For example ,a
I'm trying to store the value (different for each tabe header column) of <th>
I am simply trying to call a store procedure (SQL Server 2008) using C#
I am trying to store the state of a page in the hash. This
I have an XML document that looks like this: <?xml version=1.0 encoding=utf-8?> <Schema Namespace=EDIManagement.Models.Store
I'm trying to use Paperclip gem and store the documents on Amazon S3. In
I'm trying to make a paginate mechanism for our product documents stored in MongoDB.

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.