1.2 后端 nodejs模块mongoose - OhNaNaSun/angularBlog GitHub Wiki
mongoose
mongoose用法: mongoose入门(一)
官方api: mongoose
Schema、Model、Entity的关系请牢记,Schema生成Model,Model创造Entity,Model和Entity都可对数据库操作造成影响,但Model比Entity更具操作性。 Document可等同于Entity,具有属性和操作性 新增 如果是Entity,使用save方法,如果是Model,使用create方法
-
Model.create(doc(s), [callback])
: Shortcut for saving one or more documents to the database. MyModel.create(docs) does new MyModel(doc).save() for every doc in docs. -
Model.count(conditions, [callback])
: Counts number of matching documents in a database collection. -
Model.findOne([conditions], [projection], [options], [callback])
: Finds one document. -
Model.find(conditions, [projection], [options], [callback])
: Finds documents -
Model.remove(conditions, [callback])
: Removes documents from the collection. -
Model.update(conditions, doc, [options], [callback])
: Updates documents in the database without returning them. -
Model#save([options], [options.safe], [options.validateBeforeSave], [fn])
-
Schema#virtual(name, [options])
: Creates a virtual type with the given name. -
VirtualType#set(fn)
: Defines a setter. -
Schema#method(method, [fn])
: Adds an instance method to documents constructed from Models compiled from this schema.