Hi i inserted values into my mongodb using the following code
var mongoose = require('mongoose');
var db = mongoose.createConnection('mongodb://localhost/TruJuncSVC1');
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
console.log('connection opened in Mongodb with SAMPLE TESTING Database')
var schema = new mongoose.Schema({Response: String,Id:String,Name:String,News:String,Details:String});
var SvcOrch = db.model('SvcOrch', schema);
var data = new SvcOrch({ 'Response': 'DailyLoad','Id':'S3000981','Name':'Stears','News':'Mens Boutiques Try New Tactics for Winning Loyal CustomersTradition Finds New Biz in Old Font','Details':'Stears Roebuck and Co. or Stears, is an American chain of department stores,[2] which was founded by Richard Warren Sears and Alvah Curtis Roebuck in the late 19th century. Formerly a component of the Dow Jones Industrial Average, Stears bought out Kmart[3] in early 2005, creating the Stears Holdings Corporation.'});
data.save(function (err) {
if (err) return handleError(err);
// saved!
console.log('\nResponse data saved in MongoDB')
})
});
});
I am able to insert one value for each attribute,I need to save multiple values for a single attribut say id should have 2 or 3 values the same goes for all the attribute.Any idea as how to proceed further will be much helpful.Thanks in advance
If you need to store multiple values for a single attribute, declare it as an array.
For example, if you wanted to store multiple news items per doc, you'd change your schema to be:
var schema = new mongoose.Schema({
Response: String,
Id: String,
Name: String,
News: [String],
Details: String
});
And create new items with multiple news values as:
var data = new SvcOrch({
Response: 'DailyLoad',
Id: 'S3000981',
Name: 'Stears',
News: ['News item 1', 'News item 2'],
Details: 'More details...'
});