Create a gist now

Instantly share code, notes, and snippets.

mongoose = require('mongoose');
var _ = require('underscore');
var db = mongoose.createConnection('localhost', 'stack-test');
/* Schema definition */
var SellerSchema = new mongoose.Schema({
created: {
type: Date,
default: Date.now
},
description: {
type: String,
default: '',
trim: true
},
payment: {
type: String,
default: '',
trim: true
},
address: {
type: String,
default: '',
trim: true
},
shipping: {
type: String,
default: '',
trim: true
},
price: {
type: Number,
default: 3000,
min: 0
},
});
/* Model declaration */
var Seller = db.model('Seller', SellerSchema)
var newSeller = new Seller({ description: "stack-test", address: "aaaaa" })
newSeller.save(function(err, user) {
console.log(err)
console.log(user);
var id = user._id;
var req_body = {
description: "xxxxx",
payment: "xxxxxxxxx",
shipping: "xxxxxxx",
price: "17",
address: "xxxxxx"
};
Seller.findById(id, function (err,seller) {
seller = _.extend(seller, req_body)
seller.save(function(err) {
console.log(err);
console.log(seller);
})
});
});
{
"name": "test",
"version": "0.0.1",
"dependencies": {
"mongoose": "3.1.2",
"underscore": "~1.5.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment