Repository navigation
@142vip.nest typeorm.类.Collection
API 参考 / @142vip/nest-typeorm / Collection
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1467
The Collection class is an internal class that embodies a MongoDB collection allowing for insert/find/update/delete and other command operation on that MongoDB collection.
COLLECTION Cannot directly be instantiated
import { MongoClient } from 'mongodb'
interface Pet {
name: string
kind: 'dog' | 'cat' | 'fish'
}
const client = new MongoClient('mongodb://localhost:27017')
const pets = client.db().collection<Pet>('pets')
const petCursor = pets.find()
for await (const pet of petCursor) {
console.log(`${pet.name} is a ${pet.kind}!`)
}TSchema extends Document = Document
new Collection<
TSchema>():Collection<TSchema>
Collection<TSchema>
get bsonOptions():
BSONSerializeOptions
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1490
get collectionName():
string
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1475
The name of this collection
string
get dbName():
string
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1471
The name of the database this collection belongs to
string
get hint():
Hint|undefined
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1497
The current index hint for the collection
Hint | undefined
set hint(
v):void
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1498
Hint | undefined
void
get namespace():
string
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1479
The namespace of this collection, in the format ${this.dbName}.${this.collectionName}
string
get readConcern():
ReadConcern|undefined
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1484
The current readConcern of the collection. If not explicitly defined for this collection, will be inherited from the parent DB
ReadConcern | undefined
get readPreference():
ReadPreference|undefined
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1489
The current readPreference of the collection. If not explicitly defined for this collection, will be inherited from the parent DB
ReadPreference | undefined
get writeConcern():
WriteConcern|undefined
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1495
The current writeConcern of the collection. If not explicitly defined for this collection, will be inherited from the parent DB
WriteConcern | undefined
aggregate<
T>(pipeline?,options?):AggregationCursor<T>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1810
Execute an aggregation framework pipeline against the collection, needs MongoDB \>= 2.2
Document[]
An array of aggregation pipelines to execute
Optional settings for the command
bulkWrite(
operations,options?):Promise<BulkWriteResult>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1536
Perform a bulkWrite operation without a fluent API
Legal operation types are
insertOnereplaceOneupdateOneupdateManydeleteOnedeleteMany
If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.
AnyBulkWriteOperation<TSchema>[]
Bulk operations to perform
Optional settings for the command
Promise<BulkWriteResult>
MongoDriverError if operations is not an array
count(
filter?,options?):Promise<number>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1880
An estimated count of matching documents in the db to a filter.
NOTE: This method has been deprecated, since it does not provide an accurate count of the documents in a collection. To obtain an accurate count of documents in the collection, use countDocuments. To obtain an estimated count of all documents in the collection, use estimatedDocumentCount.
Filter<TSchema>
The filter for the count.
Optional settings for the command
Promise<number>
use countDocuments or estimatedDocumentCount instead
countDocuments(
filter?,options?):Promise<number>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1755
Gets the number of documents matching the filter. For a fast count of the total documents in a collection see estimatedDocumentCount. Note: When migrating from count to countDocuments the following query operators must be replaced:
| Operator | Replacement |
|---|---|
$where |
$expr |
$near |
$geoWithin with $center
|
$nearSphere |
$geoWithin with $centerSphere
|
The filter for the count
Optional settings for the command
Promise<number>
- https://www.mongodb.com/docs/manual/reference/operator/query/expr/
- https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
- https://www.mongodb.com/docs/manual/reference/operator/query/center/#op.\_S\_center
- https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op.\_S\_centerSphere
createIndex(
indexSpec,options?):Promise<string>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1651
Creates an index on the db and collection collection.
The field name or index specification to create an index for
Optional settings for the command
Promise<string>
const collection = client.db('foo').collection('bar')
await collection.createIndex({ a: 1, b: -1 })
// Alternate syntax for { c: 1, d: -1 } that ensures order of indexes
await collection.createIndex([[c, 1], [d, -1]])
// Equivalent to { e: 1 }
await collection.createIndex('e')
// Equivalent to { f: 1, g: 1 }
await collection.createIndex(['f', 'g'])
// Equivalent to { h: 1, i: -1 }
await collection.createIndex([{ h: 1 }, { i: -1 }])
// Equivalent to { j: 1, k: -1, l: 2d }
await collection.createIndex(['j', ['k', -1], { l: '2d' }])createIndexes(
indexSpecs,options?):Promise<string[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1683
Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher. Earlier version of MongoDB will throw a command not supported error.
Note: Unlike createIndex, this function takes in raw index specifications. Index specifications are defined here.
An array of index specifications to be created
Optional settings for the command
Promise<string[]>
const collection = client.db('foo').collection('bar');
await collection.createIndexes([
// Simple index on field fizz
{
key: { fizz: 1 },
}
// wildcard index
{
key: { '$**': 1 }
},
// named index on darmok and jalad
{
key: { darmok: 1, jalad: -1 }
name: 'tanagra'
}
]);deleteMany(
filter?,options?):Promise<DeleteResult>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1574
Delete multiple documents from a collection
Filter<TSchema>
The filter used to select the documents to remove
Optional settings for the command
Promise<DeleteResult>
deleteOne(
filter?,options?):Promise<DeleteResult>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1567
Delete a document from a collection
Filter<TSchema>
The filter used to select the document to remove
Optional settings for the command
Promise<DeleteResult>
distinct<
Key>(key):Promise<Flatten<WithId<TSchema>[Key]>[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1763
The distinct command returns a list of distinct values for the given key across a collection.
Key extends string | number | symbol
Key
Field of the document to find distinct values for
Promise<Flatten<WithId<TSchema>[Key]>[]>
distinct<
Key>(key,filter):Promise<Flatten<WithId<TSchema>[Key]>[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1764
The distinct command returns a list of distinct values for the given key across a collection.
Key extends string | number | symbol
Key
Field of the document to find distinct values for
Filter<TSchema>
The filter for filtering the set of documents to which we apply the distinct filter.
Promise<Flatten<WithId<TSchema>[Key]>[]>
distinct<
Key>(key,filter,options):Promise<Flatten<WithId<TSchema>[Key]>[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1765
The distinct command returns a list of distinct values for the given key across a collection.
Key extends string | number | symbol
Key
Field of the document to find distinct values for
Filter<TSchema>
The filter for filtering the set of documents to which we apply the distinct filter.
Optional settings for the command
Promise<Flatten<WithId<TSchema>[Key]>[]>
distinct(
key):Promise<any[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1766
The distinct command returns a list of distinct values for the given key across a collection.
string
Field of the document to find distinct values for
Promise<any[]>
distinct(
key,filter):Promise<any[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1767
The distinct command returns a list of distinct values for the given key across a collection.
string
Field of the document to find distinct values for
Filter<TSchema>
The filter for filtering the set of documents to which we apply the distinct filter.
Promise<any[]>
distinct(
key,filter,options):Promise<any[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1768
The distinct command returns a list of distinct values for the given key across a collection.
string
Field of the document to find distinct values for
Filter<TSchema>
The filter for filtering the set of documents to which we apply the distinct filter.
Optional settings for the command
Promise<any[]>
drop(
options?):Promise<boolean>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1590
Drop the collection from the database, removing it permanently. New accesses will create a new collection.
Optional settings for the command
Promise<boolean>
dropIndex(
indexName,options?):Promise<Document>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1690
Drops an index from this collection.
string
Name of the index to drop.
Optional settings for the command
Promise<Document>
dropIndexes(
options?):Promise<Document>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1696
Drops all indexes from this collection.
Optional settings for the command
Promise<Document>
estimatedDocumentCount(
options?):Promise<number>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1729
Gets an estimate of the count of documents in a collection using collection metadata. This will always run a count command on all server versions.
due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count command, which estimatedDocumentCount uses in its implementation, was not included in v1 of the Stable API, and so users of the Stable API with estimatedDocumentCount are recommended to upgrade their server version to 5.0.9+ or set apiStrict: false to avoid encountering errors.
Optional settings for the command
Promise<number>
find():
FindCursor<WithId<TSchema>>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1608
Creates a cursor for a filter that can be used to iterate over results from MongoDB
FindCursor<WithId<TSchema>>
find(
filter,options?):FindCursor<WithId<TSchema>>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1609
Creates a cursor for a filter that can be used to iterate over results from MongoDB
Filter<TSchema>
The filter predicate. If unspecified, then all documents in the collection will match the predicate
FindCursor<WithId<TSchema>>
find<
T>(filter,options?):FindCursor<T>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1610
Creates a cursor for a filter that can be used to iterate over results from MongoDB
T extends Document
Filter<TSchema>
The filter predicate. If unspecified, then all documents in the collection will match the predicate
FindCursor<T>
findOne():
Promise<WithId<TSchema> |null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1597
Fetches the first document that matches the filter
Promise<WithId<TSchema> | null>
findOne(
filter):Promise<WithId<TSchema> |null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1598
Fetches the first document that matches the filter
Filter<TSchema>
Query for find Operation
Promise<WithId<TSchema> | null>
findOne(
filter,options):Promise<WithId<TSchema> |null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1599
Fetches the first document that matches the filter
Filter<TSchema>
Query for find Operation
Optional settings for the command
Promise<WithId<TSchema> | null>
findOne<
T>():Promise<T|null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1600
Fetches the first document that matches the filter
T = TSchema
Promise<T | null>
findOne<
T>(filter):Promise<T|null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1601
Fetches the first document that matches the filter
T = TSchema
Filter<TSchema>
Query for find Operation
Promise<T | null>
findOne<
T>(filter,options?):Promise<T|null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1602
Fetches the first document that matches the filter
T = TSchema
Filter<TSchema>
Query for find Operation
Optional settings for the command
Promise<T | null>
findOneAndDelete(
filter,options?):Promise<ModifyResult<TSchema> |null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1787
Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation.
Filter<TSchema>
The filter used to select the document to remove
Optional settings for the command
Promise<ModifyResult<TSchema> | null>
findOneAndReplace(
filter,replacement,options?):Promise<ModifyResult<TSchema> |null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1795
Find a document and replace it in one atomic operation. Requires a write lock for the duration of the operation.
Filter<TSchema>
The filter used to select the document to replace
WithoutId<TSchema>
The Document that replaces the matching document
Optional settings for the command
Promise<ModifyResult<TSchema> | null>
findOneAndUpdate(
filter,update,options?):Promise<ModifyResult<TSchema> |null>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1803
Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
Filter<TSchema>
The filter used to select the document to update
UpdateFilter<TSchema>
Update operations to be performed on the document
Optional settings for the command
Promise<ModifyResult<TSchema> | null>
indexes(
options?):Promise<Document[]>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1774
Retrieve all the indexes on the collection.
Optional settings for the command
Promise<Document[]>
indexExists(
indexes,options?):Promise<boolean>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1709
Checks if one or more indexes exist on the collection, fails on first non-existing index
string | string[]
One or more index names to check.
Optional settings for the command
Promise<boolean>
indexInformation(
options?):Promise<Document>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1715
Retrieves this collections index info.
Optional settings for the command
Promise<Document>
initializeOrderedBulkOp(
options?):OrderedBulkOperation
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1867
Initiate an In order bulk write operation. Operations will be serially executed in the order they are added, creating a new operation for each switch in types.
MongoNotConnectedError
NOTE: MongoClient must be connected prior to calling this method due to a known limitation in this legacy implementation.
However, collection.bulkWrite() provides an equivalent API that does not require prior connecting.
initializeUnorderedBulkOp(
options?):UnorderedBulkOperation
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1858
Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
MongoNotConnectedError
NOTE: MongoClient must be connected prior to calling this method due to a known limitation in this legacy implementation.
However, collection.bulkWrite() provides an equivalent API that does not require prior connecting.
insertMany(
docs,options?):Promise<InsertManyResult<TSchema>>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1516
Inserts an array of documents into MongoDB. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.
OptionalUnlessRequiredId<TSchema>[]
The documents to insert
Optional settings for the command
Promise<InsertManyResult<TSchema>>
insertOne(
doc,options?):Promise<InsertOneResult<TSchema>>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1507
Inserts a single document into MongoDB. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.
OptionalUnlessRequiredId<TSchema>
The document to insert
Optional settings for the command
Promise<InsertOneResult<TSchema>>
isCapped(
options?):Promise<boolean>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1622
Returns if the collection is a capped collection
Optional settings for the command
Promise<boolean>
listIndexes(
options?):ListIndexesCursor
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1702
Get the list of all indexes information for the collection.
Optional settings for the command
options(
options?):Promise<Document>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1616
Returns the options of the collection.
Optional settings for the command
Promise<Document>
rename(
newName,options?):Promise<Collection<Document>>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1584
Rename the collection.
string
New name of of the collection.
Optional settings for the command
Promise<Collection<Document>>
This operation does not inherit options from the Db or MongoClient.
replaceOne(
filter,replacement,options?):Promise<Document|UpdateResult>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1552
Replace a document in a collection with another document
Filter<TSchema>
The filter used to select the document to replace
WithoutId<TSchema>
The Document that replaces the matching document
Optional settings for the command
Promise<Document | UpdateResult>
stats(
options?):Promise<CollStats>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1780
Get all the collection statistics.
Optional settings for the command
Promise<CollStats>
updateMany(
filter,update,options?):Promise<UpdateResult>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1560
Update multiple documents in a collection
Filter<TSchema>
The filter used to select the documents to update
UpdateFilter<TSchema>
The update operations to be applied to the documents
Optional settings for the command
Promise<UpdateResult>
updateOne(
filter,update,options?):Promise<UpdateResult>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1544
Update a single document in a collection
Filter<TSchema>
The filter used to select the document to update
UpdateFilter<TSchema> | Partial<TSchema>
The update operations to be applied to the document
Optional settings for the command
Promise<UpdateResult>
watch<
TLocal,TChange>(pipeline?,options?):ChangeStream<TLocal,TChange>
定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/driver/mongodb/typings.d.ts:1849
Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
TLocal extends Document = TSchema
Type of the data being detected by the change stream
TChange extends Document = ChangeStreamDocument<TLocal>
Type of the whole change stream document emitted
Document[]
An array of pipeline stages through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
Optional settings for the command
ChangeStream<TLocal, TChange>
watch() accepts two generic arguments for distinct use cases:
- The first is to override the schema that may be defined for this specific collection
- The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
By just providing the first argument I can type the change to be ChangeStreamDocument<{ _id: number }>
collection.watch<{ _id: number }>()
.on('change', change => console.log(change._id.toFixed(4)))Passing a second argument provides a way to reflect the type changes caused by an advanced pipeline. Here, we are using a pipeline to have MongoDB filter for insert changes only and add a comment. No need start from scratch on the ChangeStreamInsertDocument type! By using an intersection we can save time and ensure defaults remain the same type!
collection
.watch<Schema, ChangeStreamInsertDocument<Schema> & { comment: string }>([
{ $addFields: { comment: 'big changes' } },
{ $match: { operationType: 'insert' } }
])
.on('change', (change) => {
change.comment.startsWith('big')
change.operationType === 'insert'
// No need to narrow in code because the generics did that for us!
expectType<Schema>(change.fullDocument)
})- @142vip/axios
- @142vip/changelog
- @142vip/commit-linter
- @142vip/copyright
- @142vip/data-source
- @142vip/eslint-config
- @142vip/fairy-cli
- @142vip/grpc
- @142vip/nest
- @142vip/nest-redis
- @142vip/nest-typeorm
- @142vip/oauth2.0
- @142vip/open-source
- @142vip/redis
- @142vip/release-version
- @142vip/typeorm
- @142vip/utils