evanlucas / learnyoumongo

MongoDB workshop.
MIT License
306 stars 89 forks source link

Update lesson fails, even with correct solution #31

Open icodejs opened 8 years ago

icodejs commented 8 years ago

Hey,

While working on the update lesson, I wasn't able to get my code to pass, so I tried your solution and still had no luck.

I not sure if it has something to do with the versions of Node or Mongodb.

Let me know if this is enough information:

Mongodb version v3.2.1 Node v4.2.3

My solution: https://github.com/icodejs/nodeschool/blob/master/learnyoumongo/06-UPDATE/solution.js Your solution: https://github.com/evanlucas/learnyoumongo/blob/master/exercises/update/solution/solution.js

Thanks!

Bubbit commented 8 years ago

I have the same problem:

Mongodb v2.1.7 Node v5.1.0

kazzacarrot commented 7 years ago

My solution didn't pass the tests. I saw these comments and doubted the test. So, I pimped out my solution to log tinas record before and after I updated it. I saw her age change from 30 to 40 and when I ran verify, it worked! I thought I would share my working solution.

var mongo = require('mongodb').MongoClient
var url = "mongodb://localhost:27017/" + process.argv[2];
mongo.connect(url, function(err, db) {
    if (err) throw err;
    docs =  db.collection('users')
    tina = {
          username: "tinatime"
        }
    docs.find(tina).toArray(function(err, data) {
            if (err) throw err;
            console.log(data);
            docs.update(tina, { $set: {age: 40 }}, function(err
                    if (err) throw err;
                    docs.find(tina).toArray( function(err, data) {
                            if (err) throw err;
                            db.close()
                            console.log(data);
                        })
                })
    })
})