我想在_id字段中使用uuid字符串來代替ObjectId。Mongoose uuid insted ObjectId
型號/ user.js的
var uuid = require('node-uuid');
var userSchema = mongoose.Schema({
_id: {type: String, default: uuid.v4},
nick: {type: String, unique : true, default: ""},
email: {type: String, default: ""},
pass: {type: String, default: ""},
admin: {type: Boolean, default: false},
created: {type: Date, default: Date.now},
modified: {type: Date, default: Date.now}
});
獨特之處是必要的嗎?
_id: {type: String, unique : true, default: uuid.v4},
可能使用http://stackoverflow.com/questions/31900863/mongoose-does-a-custom-id-need-to-be-declared-as-an-index-and-be-unique。 – JohnnyHK