DROP
Use the drop() method to delete a table, or collection.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
db.collection("studentsdetails").drop(function(err, delOK) {
if (err) throw err;
if (delOK) console.log("Table
deleted");
db.close();
});
});
UPDATE
Use the update() method to update records, or documents.
You can update multi options.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/uki";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var myquery = { address: "Jaffna" };
var newvalues = { name:
"Mala", address: "Colombo" };
db.collection("studentsdetails").update(myquery,
newvalues, function(err, res) {
if (err) throw err;
console.log(res.result.nModified + " record updated");
db.close();
});
});
QUERY
You can find records from a table by using find() method.
var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var query = { address: /^S/ };
db.collection("studentdetails").find(query).toArray(function(err, result) {
if (err) throw err;
console.log(result);
db.close();
});
});
No comments:
Post a Comment