How to insert html tags within mongodb using nodejs
I want to insert html files into mongodb using nodejs , how will be the code structure ?
How to insert html tags within mongodb using nodejs
I want to insert html files into mongodb using nodejs , how will be the code structure ?
use this one, example of get html code frm url and save into databse
var mongoose = require("mongoose");
var request = require('request');
var dbURI = 'mongodb://localhost:27017/SOF';
// Create the database connection
mongoose.connect(dbURI);
// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection open to ' + dbURI);
});
// mongodb schema
var dataschema = new mongoose.Schema({
ofString: String,
})
var model = mongoose.model("Data", dataschema);
var Data = mongoose.model("Data");
var data = new Data();
/*
i have used request node module to get html source code from url and insert into database
*/
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
data.ofString = body;
data.save(function(err, result) {
if(err)
console.log(err);
else
console.log(result);
});
}
})
// find data
model.find({}, function(err, result) {
if(err)
console.log(err);
else
console.log(result);
});
You can store HTML parts and files in MonDOB as standard UTF-8 encoded strings, look through the documentation: MongoDB Fundamentals, and Insert Data with Node