collection is not defined in mongodb

Here your not declared the variable(collection) so that only you got this error.You need to declare that variable with proper collection name. For Example : If you are going to find the records in users collection under test schema you need to the follow the below code. var express = require(‘express’); var router = express.Router(); … Read more

In sqlite I would do, But how in mongodb c#

You can get some inspiration for updating a document in the quick-tour documentation provided on the MongoDB site: http://mongodb.github.io/mongo-csharp-driver/2.5/getting_started/quick_tour/ Just look at the Updating Document section. But to save a click you can use the following code as an inspiration: // Setup the connection to the database var client = new MongoClient(“mongodb://localhost”); var database = … Read more

Unable to delete data from mongoDB

You need to pass the _id value as an ObjectID, not a string: var mongodb = require(‘mongodb’); router.delete(‘/contact/:id’, (req, res, next) => { contact.deleteOne({ _id: new mongodb.ObjectID(req.params._id) }, function(err, result) { if (err) { res.json(err); } else { res.json(result); } }); });