1.2 后端 nodejs模块mongoose - OhNaNaSun/angularBlog GitHub Wiki

mongoose

mongoose用法: mongoose入门(一)

官方api: mongoose

👍Mongoose学习参考文档

Schema、Model、Entity的关系请牢记,Schema生成Model,Model创造Entity,Model和Entity都可对数据库操作造成影响,但Model比Entity更具操作性。 Document可等同于Entity,具有属性和操作性 新增 如果是Entity,使用save方法,如果是Model,使用create方法

  1. 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.

  2. Model.count(conditions, [callback]): Counts number of matching documents in a database collection.

  3. Model.findOne([conditions], [projection], [options], [callback]): Finds one document.

  4. Model.find(conditions, [projection], [options], [callback]): Finds documents

  5. Model.remove(conditions, [callback]): Removes documents from the collection.

  6. Model.update(conditions, doc, [options], [callback]): Updates documents in the database without returning them.

  7. Model#save([options], [options.safe], [options.validateBeforeSave], [fn])

  8. Schema#virtual(name, [options]): Creates a virtual type with the given name.

  9. VirtualType#set(fn): Defines a setter.

  10. Schema#method(method, [fn]): Adds an instance method to documents constructed from Models compiled from this schema.