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 8713457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:20:57+00:00 2026-06-13T05:20:57+00:00

{ _id: ObjectId(…), discussion_id: ObjectId(…), slug: ’34db’, posted: ISODateTime(…), author: { id: ObjectId(…), name:

  • 0
{
    _id: ObjectId(...),
    discussion_id: ObjectId(...),
    slug: '34db',
    posted: ISODateTime(...),
    author: {
              id: ObjectId(...),
              name: 'Rick'
             },
    text: 'This is so bogus ... '
}

This is what I did so far:

class Discussion
{

   /**
    * @MongoDB\Id
    */
        protected $id;

    /**
     * @MongoDB\ObjectId
     */
    protected $discussion_id;


   /**
     * @MongoDB\String
     */
    protected $slug;


    /**
     * @MongoDB\String    <---------- IS THIS THE RIGHT DATA TYPE?
     */
    protected $author;

     /**
     * @MongoDB\String
     */
    protected $text;


    /**
     * @MongoDB\Date
     */
    protected $createdAt;

}

So in my code:

  $author_info = array(
            "userName" => $userName
            );

        $discussion = new Discussion();
        $discussion->setCreatedAt(new \DateTime());
        $discussion->setAuthor($author_info);
        $discussion->setText($listingInquiry);

My question is am I doing it right? I have a feeling the author type needs to be something else. Please suggest.

Thanks

  • 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-13T05:20:58+00:00Added an answer on June 13, 2026 at 5:20 am

    If you want an ObjectId in your Author, that would be an embedded document ( or you could use a @MongoDB\Hash ).

    For an embedded document:

    /**
     * @MongoDB\EmbeddedDocument
     */
    class Author
    {
       /**
        * @MongoDB\ObjectId
        */
       protected $id;
    
       /**
        * @MongoDB\String
        */
        protected $name;
    }
    

    In your main document

    /**
     * @MongoDB\EmbedOne(targetDocument="[Namespace]\Author")
     */
     protected $author;
    

    In your code:

    $author = new Author();
    $author->setId( new \MongoId( $userId ) );
    $author->setName( "Mark" );
    
    $discussion->setAuthor( $author);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document collection like this: { _id : ObjectId(4fb21439f31dfd122ce39c4a), Name : Freelander
I have one document in my params collection like this: { _id: ObjectId(4d124cef3ffcf6f410000037), code:
I have this document stored in mongodb document: { _id:ObjectId(4eb7642ba899edcc31000001) hash:abcd123 value:some_text_here } I
I'm using this structure to store conversations & messages: { _id : ObjectId( 4f2952d7ff4b3c36d700000d
I have a basic structure like this: > db.users.findOne() { _id : ObjectId(4f384903cd087c6f720066d7), current_sign_in_at
{ _id : ObjectId(4c2209f9f3924d31102bd84a), name : mongo } what exactly is the purpose of
We have some embedded documents that look like this: { _id : ObjectId(4e402353bc9f6ec5a6000001), first_name
This is the data { username: runrun, channel: all, expire: NumberLong(1308183908743), _id: ObjectId(4df93f54e07324af47000001) }
Using mongodb with the NoRM driver I have this document: { _id : ObjectId(0758030341b870c019591900),
I have this data in Mongo: { _id: ObjectId(505fd43fdbed3dd93f0ae088), categoryName: Cat 1, services: [

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.