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();
});
});
Subscribe to:
Post Comments (Atom)
HTML introduction
HTML stands for Hyper Text Markup Language. HTML describes the structure of web page using markup. HTML elements are the building blo...
-
14TH DAY AT UKI ARRAY 1. Javascript arrays are used to store multiple values in a single variable. Example: ...
-
Firth Day at UKI ⛅personal coaching qualities of a IT field worker: self directed(don't need supervisor) ...
-
1.Create free code camp account. 2.Create trello account. 3.create slack account.
No comments:
Post a Comment