00-API-Mongoose


typora-copy-images-to: media

Mongoose

  • Mongoose() - Mongoose类的构造函数

  • Mongoose.prototype.Aggregate() - Mongoose Aggregate类的构造函数

  • Mongoose.prototype.CastError() - Mongoose CastError类的构造函数

  • Mongoose.prototype.Collection() - Mongoose Collection类的构造函数

  • Mongoose.prototype.Connection() - Mongoose Connection类的构造函数

  • Mongoose.prototype.Decimal128 - Mongoose Decimal128 SchemaTypes

  • Mongoose.prototype.Document() - Mongoose Document类的构造函数

  • Mongoose.prototype.DocumentProvider() - Mongoose DocumentProvider类的构造函数。开发者不应直接使用这个类

  • Mongoose.prototype.Error() - MongooseError 类的构造函数

  • Mongoose.prototype.Mixed - Mongoose Mixed SchemaTypes。用于在模式中声明Mongoose的更改跟踪、转换和验证应忽略的路径。

  • Mongoose.prototype.Model() - Mongoose Model类的构造函数

  • Mongoose.prototype.Mongoose() - Mongoose 类的构造函数

  • Mongoose.prototype.ObjectId - Mongoose ObjectId SchemaTypes

  • Mongoose.prototype.Promise - Mongoose Promise构造函数

  • Mongoose.prototype.PromiseProvider() - mongoose pomises的存储层

  • Mongoose.prototype.Query() - Mongoose Query类的构造函数

  • Mongoose.prototype.STATES - 向用户空间公开连接状态

  • Mongoose.prototype.Schema() - Mongoose Schema类的构造函数

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var CatSchema = new Schema(..);
  • Mongoose.prototype.SchemaType() - Mongoose SchemaType类的构造函数

  • Mongoose.prototype.SchemaTypes - Mongoose 的各种模式类型

  • Mongoose.prototype.Types - Mongoose 的各种类型

    • 类型

      • ObjectId

        Buffer

        SubDocument

        Array

        DocumentArray

  • Mongoose.prototype.VirtualType() - Mongoose VirtualType类的构造函数

  • Mongoose.prototype.connect(uri(s), [options], [callback]) - 打开默认的mongoose连接

    • 参数

      • uri(s) - String -
      • [options] - Object - 传递给MongoDB驱动程序的connect()函数,除了以下个单独说明的mongoose特定的选项外,其它参数与MongoDB驱动一致:
        • [dbName] - String - 要使用的数据的名字。如果未提供,数据库名会从连接字符串中获取
        • [user] - String - 认证用户名,等同于options.auth.user。用于保持向后兼容性。
        • [pass] - String - 认证密码,等同于options.auth.password。用于保持向后兼容性。
        • [autoIndex=true] - Boolean - Mongoose 特定选项。设置为false可禁用与此连接关联的所有模型的自动索引创建。
        • [bufferCommands=true] - Boolean - Mongoose 特定选项。设置为false可禁用与此连接关联的所有模型上的缓冲。
        • [useCreateIndex=true] - Boolean - Mongoose 特定选项。如果为true,则此连接将使用createIndex()而不是ensureIndex()通过Model.init()进行自动索引构建。
        • [useFindAndModify=true] - Boolean - 设置为false可以以使findOneAndUpdate()和findOneAndRemove()使用本机findOneAndUpdate而不是findAndModify()。
        • [useNewUrlParser=false] - Boolean - 设置为true可以使所有连接默认设置为useNewUrlParser选项。
      • [callback] - Function -
    • 返回

      • Promise 如果连接成功,则为resolve状态的this
    • 示例

    mongoose.connect('mongodb://user:pass@localhost:port/database');
    
      // replica sets
      var uri = 'mongodb://user:pass@localhost:port,anotherhost:port,yetanother:port/mydatabase';
      mongoose.connect(uri);
    
      // with options
      mongoose.connect(uri, options);
    
      // optional callback that gets fired when initial connection completed
      var uri = 'mongodb://nonexistent.domain:27000';
      mongoose.connect(uri, function(error) {
        // if error is truthy, the initial connection failed.
      })
    
  • Mongoose.prototype.connection - mongoose模块的默认连接

    默认情况下这个connection为使用mongoose.model创建的每个模型所使用的连接。

    返回

    示例

    var mongoose = require('mongoose');
    mongoose.connect(...);
    mongoose.connection.on('error', cb);
    
  • Mongoose.prototype.createConnection() - 创建一个Connection实例

    每个connection实例都映射到一个数据库,同时管理多个数据库连接时,这个方法很有用。

    参数

    • uri - String - MongoDB连接字符串,结构:mongodb://URI
    • [options] - Object - 传递给MongoDB驱动程序的connect()函数,除了以下个单独说明的mongoose特定的选项外,其它参数与MongoDB驱动一致:
      • [user] - String - 认证用户名,等同于options.auth.user。用于保持向后兼容性。
      • [pass] - String - 认证密码,等同于options.auth.password。用于保持向后兼容性。
      • [autoIndex=true] - Boolean - Mongoose 特定选项。设置为false可禁用与此连接关联的所有模型的自动索引创建。
      • [bufferCommands=true] - Boolean - Mongoose 特定选项。设置为false可禁用与此连接关联的所有模型上的缓冲。

    以上参数中,传递的options中的选项优先于连接字符串中所包含的选项。
    返回

    • Connection 所创建的 Connection 对象。该对象是一个 thenable 对象,所以你可以await mongoose.createConnection()

    示例

     // with mongodb:// URI
      db = mongoose.createConnection('mongodb://user:pass@localhost:port/database');
    
      // and options
      var opts = { db: { native_parser: true }}
      db = mongoose.createConnection('mongodb://user:pass@localhost:port/database', opts);
    
      // replica sets
      db = mongoose.createConnection('mongodb://user:pass@localhost:port,anotherhost:port,yetanother:port/database');
    
      // and options
      var opts = { replset: { strategy: 'ping', rs_name: 'testSet' }}
      db = mongoose.createConnection('mongodb://user:pass@localhost:port,anotherhost:port,yetanother:port/database', opts);
    
      // and options
      var opts = { server: { auto_reconnect: false }, user: 'username', pass: 'mypassword' }
      db = mongoose.createConnection('localhost', 'database', port, opts)
    
      // initialize now, connect later
      db = mongoose.createConnection();
      db.open('localhost', 'database', port, [opts]);
    
  • Mongoose.prototype.deleteModel()

  • Mongoose.prototype.disconnect()

  • Mongoose.prototype.get()

  • Mongoose.prototype.model()

  • Mongoose.prototype.modelNames()

  • Mongoose.prototype.mongo

  • Mongoose.prototype.mquery

  • Mongoose.prototype.now()

  • Mongoose.prototype.plugin()

  • Mongoose.prototype.pluralize()

  • Mongoose.prototype.set()

  • Mongoose.prototype.startSession()

  • Mongoose.prototype.version

Schema

  • Schema()

  • Schema.Types

  • Schema.indexTypes

  • Schema.prototype.add()

  • Schema.prototype.childSchemas

  • Schema.prototype.clone()

  • Schema.prototype.eachPath()

  • Schema.prototype.get()

  • Schema.prototype.index()

  • Schema.prototype.indexes()

  • Schema.prototype.loadClass()

  • Schema.prototype.method()

  • Schema.prototype.obj

  • Schema.prototype.path()

  • Schema.prototype.pathType()

  • Schema.prototype.plugin()

  • Schema.prototype.post()

  • Schema.prototype.pre()

  • Schema.prototype.queue()

  • Schema.prototype.remove()

  • Schema.prototype.requiredPaths()

  • Schema.prototype.set()

  • Schema.prototype.static()

  • Schema.prototype.virtual()

  • Schema.prototype.virtualpath()

  • Schema.reserved

Connection

  • Connection()

  • Connection.prototype.close()

  • Connection.prototype.collection()

  • Connection.prototype.collections

  • Connection.prototype.config

  • Connection.prototype.createCollection()

  • Connection.prototype.db

  • Connection.prototype.deleteModel()

  • Connection.prototype.dropCollection()

  • Connection.prototype.dropDatabase()

  • Connection.prototype.host

  • Connection.prototype.model()

  • Connection.prototype.modelNames()

  • Connection.prototype.name

  • Connection.prototype.pass

  • Connection.prototype.port

  • Connection.prototype.readyState

  • Connection.prototype.startSession()

  • Connection.prototype.useDb()

  • Connection.prototype.user

Document

  • Document.prototype.$ignore()

  • Document.prototype.$isDefault()

  • Document.prototype.$isDeleted()

  • Document.prototype.$markValid()

  • Document.prototype.$session()

  • Document.prototype.$set()

  • Document.prototype.depopulate()

  • Document.prototype.equals()

  • Document.prototype.errors

  • Document.prototype.execPopulate()

  • Document.prototype.get()

  • Document.prototype.id

  • Document.prototype.init()

  • Document.prototype.inspect()

  • Document.prototype.invalidate()

  • Document.prototype.isDirectModified()

  • Document.prototype.isDirectSelected()

  • Document.prototype.isInit()

  • Document.prototype.isModified()

  • Document.prototype.isNew

  • Document.prototype.isSelected()

  • Document.prototype.markModified()

  • Document.prototype.modifiedPaths()

  • Document.prototype.populate()

  • Document.prototype.populated()

  • Document.prototype.replaceOne()

  • Document.prototype.save()

  • Document.prototype.schema

  • Document.prototype.set()

  • Document.prototype.toJSON()

  • Document.prototype.toObject()

  • Document.prototype.toString()

  • Document.prototype.unmarkModified()

  • Document.prototype.update()

  • Document.prototype.updateOne()

  • Document.prototype.validate()

  • Document.prototype.validateSync()

Model

  • Model()

  • Model.aggregate()

  • Model.bulkWrite()

  • Model.count()

  • Model.countDocuments()

  • Model.create()

  • Model.createCollection()

  • Model.createIndexes()

  • Model.deleteMany()

  • Model.deleteOne()

  • Model.discriminator()

  • Model.distinct()

  • Model.ensureIndexes()

  • Model.estimatedDocumentCount()

  • Model.find()

  • Model.findById()

  • Model.findByIdAndDelete()

  • Model.findByIdAndRemove()

  • Model.findByIdAndUpdate()

  • Model.findOne()

  • Model.findOneAndDelete()

  • Model.findOneAndRemove()

  • Model.findOneAndUpdate()

  • Model.geoSearch()

  • Model.hydrate()

  • Model.init()

  • Model.insertMany()

  • Model.listIndexes()

  • Model.mapReduce()

  • Model.populate()

  • Model.prototype.$where

  • Model.prototype.$where()

  • Model.prototype.base

  • Model.prototype.baseModelName

  • Model.prototype.collection

  • Model.prototype.db

  • Model.prototype.discriminators

  • Model.prototype.increment()

  • Model.prototype.model()

  • Model.prototype.modelName

  • Model.prototype.remove()

  • Model.prototype.save()

  • Model.prototype.schema

  • Model.prototype.delete

  • Model.remove()

  • Model.replaceOne()

  • Model.startSession()

  • Model.syncIndexes()

  • Model.translateAliases()

  • Model.update()

  • Model.updateMany()

  • Model.updateOne()

  • Model.watch()

  • Model.where()

Query

  • Query()

  • Query.prototype.$where()

  • Query.prototype.Symbol.asyncIterator()

  • Query.prototype.all()

  • Query.prototype.and()

  • Query.prototype.batchSize()

  • Query.prototype.box()

  • Query.prototype.cast()

  • Query.prototype.catch()

  • Query.prototype.center()

  • Query.prototype.centerSphere()

  • Query.prototype.circle()

  • Query.prototype.collation()

  • Query.prototype.comment()

  • Query.prototype.count()

  • Query.prototype.countDocuments()

  • Query.prototype.cursor()

  • Query.prototype.deleteMany()

  • Query.prototype.deleteOne()

  • Query.prototype.distinct()

  • Query.prototype.elemMatch()

  • Query.prototype.equals()

  • Query.prototype.error()

  • Query.prototype.estimatedDocumentCount()

  • Query.prototype.exec()

  • Query.prototype.exists()

  • Query.prototype.explain()

  • Query.prototype.find()

  • Query.prototype.findOne()

  • Query.prototype.findOneAndDelete()

  • Query.prototype.findOneAndRemove()

  • Query.prototype.findOneAndUpdate()

  • Query.prototype.geometry()

  • Query.prototype.getOptions()

  • Query.prototype.getPopulatedPaths()

  • Query.prototype.getQuery()

  • Query.prototype.getUpdate()

  • Query.prototype.gt()

  • Query.prototype.gte()

  • Query.prototype.hint()

  • Query.prototype.in()

  • Query.prototype.intersects()

  • Query.prototype.j()

  • Query.prototype.lean()

  • Query.prototype.limit()

  • Query.prototype.lt()

  • Query.prototype.lte()

  • Query.prototype.map()

  • Query.prototype.maxDistance()

  • Query.prototype.maxScan()

  • Query.prototype.maxscan()

  • Query.prototype.merge()

  • Query.prototype.mod()

  • Query.prototype.mongooseOptions()

  • Query.prototype.ne()

  • Query.prototype.near()

  • Query.prototype.nearSphere()

  • Query.prototype.nin()

  • Query.prototype.nor()

  • Query.prototype.or()

  • Query.prototype.orFail()

  • Query.prototype.polygon()

  • Query.prototype.populate()

  • Query.prototype.read()

  • Query.prototype.readConcern()

  • Query.prototype.regex()

  • Query.prototype.remove()

  • Query.prototype.replaceOne()

  • Query.prototype.select()

  • Query.prototype.selected()

  • Query.prototype.selectedExclusively()

  • Query.prototype.selectedInclusively()

  • Query.prototype.session()

  • Query.prototype.set()

  • Query.prototype.setOptions()

  • Query.prototype.setQuery()

  • Query.prototype.setUpdate()

  • Query.prototype.size()

  • Query.prototype.skip()

  • Query.prototype.slaveOk()

  • Query.prototype.slice()

  • Query.prototype.snapshot()

  • Query.prototype.sort()

  • Query.prototype.tailable()

  • Query.prototype.then()

  • Query.prototype.toConstructor()

  • Query.prototype.update()

  • Query.prototype.updateMany()

  • Query.prototype.updateOne()

  • Query.prototype.use$geoWithin

  • Query.prototype.w()

  • Query.prototype.where()

  • Query.prototype.within()

  • Query.prototype.wtimeout()

Aggregate

  • Aggregate()

  • Aggregate.prototype.Symbol.asyncIterator()

  • Aggregate.prototype.addCursorFlag()

  • Aggregate.prototype.addFields()

  • Aggregate.prototype.allowDiskUse()

  • Aggregate.prototype.append()

  • Aggregate.prototype.collation()

  • Aggregate.prototype.count()

  • Aggregate.prototype.cursor()

  • Aggregate.prototype.exec()

  • Aggregate.prototype.explain()

  • Aggregate.prototype.facet()

  • Aggregate.prototype.graphLookup()

  • Aggregate.prototype.group()

  • Aggregate.prototype.hint()

  • Aggregate.prototype.limit()

  • Aggregate.prototype.lookup()

  • Aggregate.prototype.match()

  • Aggregate.prototype.model()

  • Aggregate.prototype.near()

  • Aggregate.prototype.option()

  • Aggregate.prototype.options

  • Aggregate.prototype.pipeline()

  • Aggregate.prototype.project()

  • Aggregate.prototype.read()

  • Aggregate.prototype.readConcern()

  • Aggregate.prototype.redact()

  • Aggregate.prototype.replaceRoot()

  • Aggregate.prototype.sample()

  • Aggregate.prototype.session()

  • Aggregate.prototype.skip()

  • Aggregate.prototype.sort()

  • Aggregate.prototype.sortByCount()

  • Aggregate.prototype.then()

  • Aggregate.prototype.unwind()

SchemaType

  • SchemaType()

  • SchemaType.prototype.default()

  • SchemaType.prototype.get()

  • SchemaType.prototype.index()

  • SchemaType.prototype.required()

  • SchemaType.prototype.select()

  • SchemaType.prototype.set()

  • SchemaType.prototype.sparse()

  • SchemaType.prototype.text()

  • SchemaType.prototype.unique()

  • SchemaType.prototype.validate()

VirtualType

  • VirtualType()

  • VirtualType.prototype._applyDefaultGetters()

  • VirtualType.prototype.applyGetters()

  • VirtualType.prototype.applySetters()

  • VirtualType.prototype.get()

  • VirtualType.prototype.set()

MongooseError

  • MongooseError.CastError

  • MongooseError.DivergentArrayError

  • MongooseError.DocumentNotFoundError

  • MongooseError.MissingSchemaError

  • MongooseError.OverwriteModelError

  • MongooseError.ParallelSaveError

  • MongooseError.ValidationError

  • MongooseError.ValidatorError

  • MongooseError.VersionError

  • MongooseError.messages

MongooseArray

  • MongooseArray.prototype.$pop()

  • MongooseArray.prototype.$shift()

  • MongooseArray.prototype.addToSet()

  • MongooseArray.prototype.indexOf()

  • MongooseArray.prototype.inspect()

  • MongooseArray.prototype.nonAtomicPush()

  • MongooseArray.prototype.pop()

  • MongooseArray.prototype.pull()

  • MongooseArray.prototype.push()

  • MongooseArray.prototype.remove()

  • MongooseArray.prototype.set()

  • MongooseArray.prototype.shift()

  • MongooseArray.prototype.sort()

  • MongooseArray.prototype.splice()

  • MongooseArray.prototype.toObject()

  • MongooseArray.prototype.unshift()

原文地址:https://www.cnblogs.com/pikachu/p/14690751.html