removed old tests, created new ones and format
This commit is contained in:
parent
7579afa3c3
commit
b03231b849
57 changed files with 4092 additions and 5901 deletions
|
|
@ -374,13 +374,13 @@ export class MongoDBClient {
|
|||
): Promise<any> {
|
||||
const collection = this.getCollection(collectionName, dbName);
|
||||
const now = new Date();
|
||||
|
||||
|
||||
const docsWithTimestamps = documents.map(doc => ({
|
||||
...doc,
|
||||
created_at: (doc as any).created_at || now,
|
||||
updated_at: now,
|
||||
}));
|
||||
|
||||
|
||||
const result = await collection.insertMany(docsWithTimestamps as any, options);
|
||||
return {
|
||||
insertedCount: result.insertedCount,
|
||||
|
|
@ -399,7 +399,7 @@ export class MongoDBClient {
|
|||
): Promise<T[]> {
|
||||
const collection = this.getCollection(collectionName, dbName);
|
||||
const cursor = collection.find(filter, options);
|
||||
return await cursor.toArray() as T[];
|
||||
return (await cursor.toArray()) as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -427,14 +427,14 @@ export class MongoDBClient {
|
|||
dbName?: string
|
||||
): Promise<any> {
|
||||
const collection = this.getCollection(collectionName, dbName);
|
||||
|
||||
|
||||
// Add updated_at timestamp
|
||||
if (update.$set) {
|
||||
update.$set.updated_at = new Date();
|
||||
} else if (!update.$setOnInsert && !update.$unset && !update.$inc) {
|
||||
update = { $set: { ...update, updated_at: new Date() } };
|
||||
}
|
||||
|
||||
|
||||
const result = await collection.updateOne(filter, update, options);
|
||||
return {
|
||||
matchedCount: result.matchedCount,
|
||||
|
|
@ -455,14 +455,14 @@ export class MongoDBClient {
|
|||
dbName?: string
|
||||
): Promise<any> {
|
||||
const collection = this.getCollection(collectionName, dbName);
|
||||
|
||||
|
||||
// Add updated_at timestamp
|
||||
if (update.$set) {
|
||||
update.$set.updated_at = new Date();
|
||||
} else if (!update.$setOnInsert && !update.$unset && !update.$inc) {
|
||||
update = { $set: { ...update, updated_at: new Date() } };
|
||||
}
|
||||
|
||||
|
||||
const result = await collection.updateMany(filter, update, options);
|
||||
return {
|
||||
matchedCount: result.matchedCount,
|
||||
|
|
@ -528,7 +528,7 @@ export class MongoDBClient {
|
|||
): Promise<T[]> {
|
||||
const collection = this.getCollection(collectionName, dbName);
|
||||
const cursor = collection.aggregate(pipeline, options);
|
||||
return await cursor.toArray() as T[];
|
||||
return (await cursor.toArray()) as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -560,10 +560,7 @@ export class MongoDBClient {
|
|||
/**
|
||||
* List all indexes on a collection
|
||||
*/
|
||||
async listIndexes(
|
||||
collectionName: string,
|
||||
dbName?: string
|
||||
): Promise<any[]> {
|
||||
async listIndexes(collectionName: string, dbName?: string): Promise<any[]> {
|
||||
const collection = this.getCollection(collectionName, dbName);
|
||||
const cursor = collection.listIndexes();
|
||||
return await cursor.toArray();
|
||||
|
|
@ -579,11 +576,7 @@ export class MongoDBClient {
|
|||
/**
|
||||
* Create a new collection
|
||||
*/
|
||||
async createCollection(
|
||||
collectionName: string,
|
||||
options?: any,
|
||||
dbName?: string
|
||||
): Promise<void> {
|
||||
async createCollection(collectionName: string, options?: any, dbName?: string): Promise<void> {
|
||||
const db = this.getDatabase(dbName);
|
||||
await db.createCollection(collectionName, options);
|
||||
}
|
||||
|
|
@ -591,10 +584,7 @@ export class MongoDBClient {
|
|||
/**
|
||||
* Drop a collection
|
||||
*/
|
||||
async dropCollection(
|
||||
collectionName: string,
|
||||
dbName?: string
|
||||
): Promise<void> {
|
||||
async dropCollection(collectionName: string, dbName?: string): Promise<void> {
|
||||
const db = this.getDatabase(dbName);
|
||||
await db.dropCollection(collectionName);
|
||||
}
|
||||
|
|
@ -602,10 +592,7 @@ export class MongoDBClient {
|
|||
/**
|
||||
* List all collections in a database
|
||||
*/
|
||||
async listCollections(
|
||||
filter: any = {},
|
||||
dbName?: string
|
||||
): Promise<any[]> {
|
||||
async listCollections(filter: any = {}, dbName?: string): Promise<any[]> {
|
||||
const db = this.getDatabase(dbName);
|
||||
const collections = await db.listCollections(filter).toArray();
|
||||
return collections;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue