Live data from Hacker News

MongoDB interactive tutorial

mongly.com

21–26 of 26 posts

Re: MongoDB interactive tutorial

#21
post #12

In the real world you probably wouldn't want to have a dob field on the unicorns table. Instead just use the timestamp embedded into the _id field. Pretty good overall though.

"In the real world you probably wouldn't want to have a dob field on the unicorns table. Instead just use the timestamp embedded into the _id field."

The real world unicorns are not born on the same second that their db record is created.

Re: MongoDB interactive tutorial

#22
post #12

In the real world you probably wouldn't want to have a dob field on the unicorns table. Instead just use the timestamp embedded into the _id field. Pretty good overall though.

The issue with that is if your DB gets backed and starts queuing writes, the timestamps will be skewed. Obviously this isn't always a show stopper, but a caveat nonetheless.

Re: MongoDB interactive tutorial

#23

Lesson 6 asks for 'Here's a tricky one: get ONLY the NAMES of the 2nd and 3rd heaviest male unicorns' Which made me query: db.unicorns.find({gender:'m'}, {name:1, _id:0}).sort({weight:-1}).skip(1).limit(2) but it wants: db.unicorns.find({gender:'m'}, {name:1}).sort({weight:-1}).skip(1).limit(2)

Lesson 7 quit on me. How do I skip lessons? Ze mouze clickz, zey do nottingz.

Re: MongoDB interactive tutorial

#24
post #12

In the real world you probably wouldn't want to have a dob field on the unicorns table. Instead just use the timestamp embedded into the _id field. Pretty good overall though.

The issue with that is if your DB gets backed and starts queuing writes, the timestamps will be skewed. Obviously this isn't always a show stopper, but a caveat nonetheless.

Actually the _id is usually created client-side so the timestamp will reflect when the application created the object rather than when it was processed by the DB. The only major exception is when the DB creates the _id for an upsert.

Re: MongoDB interactive tutorial

#25
post #23

Lesson 6 asks for 'Here's a tricky one: get ONLY the NAMES of the 2nd and 3rd heaviest male unicorns' Which made me query: db.unicorns.find({gender:'m'}, {name:1, _id:0}).sort({weight:-1}).skip(1).limit(2) but it wants: db.unicorns.find({gender:'m'}, {name:1}).sort({weight:-1}).skip(1).limit(2)

Lesson 7 quit on me. How do I skip lessons? Ze mouze clickz, zey do nottingz.

lesson(8);

Re: MongoDB interactive tutorial

#26
A few latency issues... or is it just tutorial related sluggishness or is it representative of Mongos' CAP tradeoffs? I guess 'eventually consistent' kicked in by the second find query. If that is what really happened, it is really cool to visualize 'eventually consistent'!

Output from back to back db.users.find() command. It took a while for Johnny to be updated to Cash.

> db.users.find();

[ { "_id" : { "$oid" : "4d82805ecc9374271b03dd8a" }, "name" : "Johnny", "languages" : [ "ruby", "c" ] }, { "_id" : { "$oid" : "4d828066cc9374271b03dd8b" }, "name" : "Sue", "languages" : [ "scala", "lisp" ] } ]

> db.users.find();

[ { "_id" : { "$oid" : "4d82805ecc9374271b03dd8a" }, "name" : "Cash", "languages" : [ "english" ] }, { "_id" : { "$oid" : "4d828066cc9374271b03dd8b" }, "name" : "Sue", "languages" : [ "scala", "lisp" ] } ] >

Ed: Oops. I was on the try.mongodb.org page. Not the linked article. I am trying that now.

Post reply on HN