Answer the question
In order to leave comments, you need to log in
Creating nested documents in PHP/MongoDB?
How to create a subdocument? There is a lot of information on the Internet on how to update (add) a nested document, but what if I don’t have a collection yet, but I need to immediately create its structure, with nested documents? I feel it is very simple :-)
$query = array(
'author' => 'admin',
'post' => array(
'title' => '1',
'body' => '1'
),
)
$collection->insert($query);
{
"_id" : ObjectId("4e5276adbd1ac4242b000002"),
"author" : "admin",
"post" :
{
"title" : "1",
"body" : "1"
}
}
{
"_id" : ObjectId("4e5276adbd1ac4242b000002"),
"author" : "admin",
"post" :
[
{
"title" : "1",
"body" : "1"
}
]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question