{
_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
If you want an
ObjectIdin your Author, that would be an embedded document ( or you could use a@MongoDB\Hash).For an embedded document:
In your main document
In your code: