Created
December 4, 2013 11:47
-
-
Save anthonny/7786310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}) | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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