vendredi 17 octobre 2014

updating embedded document array with mongoose


Vote count:

0




How to update the record using the monngose, with the given schema,i have below sample embedeed document defined in mongo db\



{
"_id":"Orders",
"data":[
{
"view":"145",
"date":"2001/00/10"
}
]
}


i have defined the Model.js that connect with mongo db, and defined the scheme here


Model.js



var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/stack');

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));


var stackSchema = mongoose.Schema({
name: String
})

var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;

var tagData = new Schema(
{
Orders_Number : ObjectId,
data :[viewData]
}
)
var viewData = new Schema({
view : String,
date : Date
});


module.exports = mongoose.model('Tag', tagData);
module.exports = mongoose.model('View', viewData);


how to update the docunemt ? My Test.js



var View = require('./Model');
var Tag = require('./Model');


var view = new View({
"view" : "700",
"date" : "2001/1/20"

});

var tag = new Tag(
{
"_id" : "13224324"
},
{
$pushAll : {
data : [ view ]
}
});


is the declaration is right ? to the sample json ? and finally how to update, when i try updating it's not reflection in the mongodb



asked 1 min ago

anish

1,023






updating embedded document array with mongoose

Aucun commentaire:

Enregistrer un commentaire