Skip to content

Instantly share code, notes, and snippets.

@anthonny
Created December 4, 2013 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonny/7786310 to your computer and use it in GitHub Desktop.
Save anthonny/7786310 to your computer and use it in GitHub Desktop.
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