evanlucas / learnyoumongo

MongoDB workshop.
MIT License
306 stars 89 forks source link

remove doesn't work #56

Open kazzacarrot opened 7 years ago

kazzacarrot commented 7 years ago

After my solution didn't pass, and I couldn't debug my own, I copied your solution into "re.js" and ran 'learnyoumongo run re.js` -> This is the output

Expected document to be removed [ { _id: '554a655c0639034860349353', name: 'blah' } ]
hwangm commented 7 years ago

@kazzacarrot Here's my code if you want to compare - it passes run and verify. In the official MongoDB Node api notes, remove() has been deprecated in favor of deleteOne() or deleteMany().


var mongo = require('mongodb').MongoClient;

var url = 'mongodb://localhost:27017/'+process.argv[2];

mongo.connect(url, (err, db) => {
        if (err) throw err;
        var coll = db.collection(process.argv[3]);
        var id = process.argv[4];
        coll.deleteOne({
                _id: id
        }, (err, data) => {
                if (err) throw err;
                db.close();
        });
});
snehal96 commented 6 years ago

@hwangm, I copy pasted your code and it still shows the same error for me. 












Expected document to be removed [ { _id: '554a655c0639034860349353', name: 'blah' } ]

Mongodb version: 




 MongoDB shell version v3.6.2 git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420 OpenSSL version: OpenSSL 1.0.0-fips 29 Mar 2010 allocator: tcmalloc modules: none build environment: distmod: amazon distarch: x86_64 target_arch: x86_64

P.S.: I am using amazon clod 9 ide.

hwangm commented 6 years ago

@snehal96 Have you looked at the solutions updated for mongodb 3+? https://github.com/nachoperassi/learnyoumongo

Perhaps there was some change that makes my solution invalid now, I'm not sure since it was a while ago now.