Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Why do I have two records with the same Author Id?

db.posts.find({},{"_id":false,author:true})

{ "author" : ObjectId("5737abb574547531183e957c") }

{ "author" : ObjectId("5737abb574547531183e957d") }

{ "author" : ObjectId("5737abb574547531183e957e") }

{ "author" : ObjectId("5737abb574547531183e957c") }

db.posts.update({author:ObjectId("5737abb574547531183e957c")},{$set:{tags ['foo','bar'],title:"title update"}})

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

db.posts.find({author:ObjectId("5737abb574547531183e957c")},{title:true})

{ "_id" : ObjectId("5737abb574547531183e9581"), "title" : "title update" }

{ "_id" : ObjectId("5737abb574547531183e9584"), "title" : "Parenting 101" }

db.posts.find({},{title:true,author:true,_id:false})

{ "title" : "title update", "author" : ObjectId("5737abb574547531183e957c") }

{ "title" : "I love the holidays", "author" : ObjectId("5737abb574547531183e957d") }

{ "title" : "How to workout", "author" : ObjectId("5737abb574547531183e957e") }

{ "title" : "Parenting 101", "author" : ObjectId("5737abb574547531183e957c") }

1 Answer

I'm guessing in the table it looks kinda like this structure:

title                    authorID
--------                -----------
Parenting 101     1
parenting 201    1

If thats the case then the reason there is two rows with same author ID is because the author has two titles and each unique title has it's own row, so to denote that both titles are from that specific author you give the title the author/id.