exports.User = mongolass.model('User', {
name: { type: 'string' },
password: { type: 'string' },
avatar: { type: 'string' },
gender: { type: 'string', enum: ['m', 'f', 'x'] },
bio: { type: 'string' }
});
exports.User.index({ name: 1 }, { unique: true }).exec();// 根据用户名找到用户,用户名全局唯一
这是什么意思呀?丝毫不懂
Why not use mongoose? There are many tutorials on this
It means that a collection model has been established to define the fields and the value types of the fields. Previously, it corresponded to the collection Users in Mongodb. After mongolass2.4.5, it corresponds to the collection named User in the database. All subsequent additions, deletions, and modifications will be checked through this Model object operations, such as User.insert User.find, etc.
The following sentence
means that an index in positive order by name has been established and cannot be repeated
As for how to connect, it is in the original author's document. The configuration is written in default.js in the config. Then use
mongolass.connect(config.mongodb);
and you will be connected