Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I have made a collection "post" just as a tester which for now includes 2 documents. It has an embedded collection "comments" where i have entered 2 docs. A comment has a 'title', 'content' and 'likes'. I would like to know how could I add another field which is a collection named 'replies'(Basically replies to the comments)?
Here is my insert code for the initial documents:
post=db.post
post.insert
(
	[
		{title:"My first Post",
		content:"Hello World this is my first post 		at the website!!!",
		time: new Date(),
		by:{
			name: "Mohit Hiralal",
			email:"mh@gmail.com"}
		},
		{title:"My second post",
		content:"This is my second post. Hope this garners some atention!",
		time: new Date(),
		by{
name:"Mohit",email:"m@gmail.com"
		},
		comments:
		[
			{title:"Spelling wrong",
			content:"You spelled attenttion wrong…",
			likes:1009}
		]
		}
]
)
Posted
Updated 5-Aug-15 5:15am
v5
Comments
Sergey Alexandrovich Kryukov 5-Aug-15 11:16am    
Please don't re-post; by obvious reasons, it's considered as abuse.
—SA
Mohit Hiralal 5-Aug-15 12:45pm    
What are you saying?
Sergey Alexandrovich Kryukov 5-Aug-15 12:47pm    
Which part of my comment you did not understand?
—SA
Mohit Hiralal 5-Aug-15 12:49pm    
re-post. Why would you say it has been re-posted? This is my own question.
Sergey Alexandrovich Kryukov 5-Aug-15 13:00pm    
Please see http://www.codeproject.com/Questions/1016338/Update-embedded-documents-in-MongoDB.
Can you explain this re-post then? Don't you have two different accounts?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900