node.js - 怎么使用mongolass驱动库连接mongodb数据库呀?
巴扎黑
巴扎黑 2017-04-17 16:32:18
0
2
634

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();// 根据用户名找到用户,用户名全局唯一

这是什么意思呀?丝毫不懂

巴扎黑
巴扎黑

reply all(2)
PHPzhong

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

exports.User.index({ name: 1 }, { unique: true }).exec()

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template