fix(core): update
This commit is contained in:
parent
a877616739
commit
2d2bb50578
@ -27,10 +27,7 @@ tap.test('should add a mongotarget to mongodump instance', async () => {
|
|||||||
|
|
||||||
tap.test('should dump a collection to a directory', async () => {
|
tap.test('should dump a collection to a directory', async () => {
|
||||||
const target = await testMongodump.addMongoTargetByMongoDescriptor(await testSmartMongo.getMongoDescriptor());
|
const target = await testMongodump.addMongoTargetByMongoDescriptor(await testSmartMongo.getMongoDescriptor());
|
||||||
const collections = await target.getCollections();
|
await target.dumpAllCollectionsToDir('.nogit', docArg => docArg.id, true);
|
||||||
for (const collection of collections) {
|
|
||||||
await target.dumpCollectionToDir(collection, '.nogit', doc => doc.id);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.test('should stop the smartmongo instance', async () => {
|
tap.test('should stop the smartmongo instance', async () => {
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/mongodump',
|
name: '@pushrocks/mongodump',
|
||||||
version: '1.0.4',
|
version: '1.0.5',
|
||||||
description: 'a tool to handle dumps of mongodb databases'
|
description: 'a tool to handle dumps of mongodb databases'
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@ import * as plugins from './mongodump.plugins.js';
|
|||||||
* + exposes functions to interact with the dump target
|
* + exposes functions to interact with the dump target
|
||||||
*/
|
*/
|
||||||
export class MongoDumpTarget {
|
export class MongoDumpTarget {
|
||||||
public static async createAndInit(
|
public static async createAndInit(mongoDescriptorArg: plugins.tsclass.database.IMongoDescriptor) {
|
||||||
mongoDescriptorArg: plugins.tsclass.database.IMongoDescriptor
|
|
||||||
) {
|
|
||||||
const mongoDumpTarget = new MongoDumpTarget(mongoDescriptorArg);
|
const mongoDumpTarget = new MongoDumpTarget(mongoDescriptorArg);
|
||||||
await mongoDumpTarget.init();
|
await mongoDumpTarget.init();
|
||||||
return mongoDumpTarget;
|
return mongoDumpTarget;
|
||||||
@ -61,19 +59,48 @@ export class MongoDumpTarget {
|
|||||||
/**
|
/**
|
||||||
* dumps a collection to a directory
|
* dumps a collection to a directory
|
||||||
*/
|
*/
|
||||||
public async dumpCollectionToDir(collectionArg: plugins.mongodb.Collection, dirArg: string, nameTransformFunction = (doc: any) => doc._id) {
|
public async dumpCollectionToDir(
|
||||||
|
collectionArg: plugins.mongodb.Collection,
|
||||||
|
dirArg: string,
|
||||||
|
nameTransformFunction = (doc: any) => doc._id
|
||||||
|
) {
|
||||||
const dirPath = plugins.smartpath.transform.makeAbsolute(dirArg);
|
const dirPath = plugins.smartpath.transform.makeAbsolute(dirArg);
|
||||||
const collectionDir = plugins.path.join(dirPath, collectionArg.collectionName);
|
const collectionDir = plugins.path.join(dirPath, collectionArg.collectionName);
|
||||||
await plugins.smartfile.fs.ensureDir(collectionDir);
|
await plugins.smartfile.fs.ensureDir(collectionDir);
|
||||||
const cursor = collectionArg.find();
|
const cursor = collectionArg.find();
|
||||||
let value = await cursor.next();
|
let value = await cursor.next();
|
||||||
while (value) {
|
while (value) {
|
||||||
await plugins.smartfile.memory.toFs(JSON.stringify(value, null, 2), plugins.path.join(collectionDir, `${nameTransformFunction(value)}.json`));
|
await plugins.smartfile.memory.toFs(
|
||||||
|
JSON.stringify(value, null, 2),
|
||||||
|
plugins.path.join(collectionDir, `${nameTransformFunction(value)}.json`)
|
||||||
|
);
|
||||||
value = await cursor.next();
|
value = await cursor.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async dumpCollectionToTarArchive(collectionArg: plugins.mongodb.Collection) {}
|
public async dumpCollectionToTarArchiveStream(collectionArg: plugins.mongodb.Collection) {}
|
||||||
|
|
||||||
public async dumpAllCollectionsToDir() {}
|
public async dumpCollectionToTarArchiveFile(
|
||||||
|
collectionArg: plugins.mongodb.Collection,
|
||||||
|
filePathArg: string
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public async dumpAllCollectionsToDir(
|
||||||
|
dirArg: string,
|
||||||
|
nameFunctionArg?: (docArg: any) => string,
|
||||||
|
cleanDirArg = false
|
||||||
|
) {
|
||||||
|
if (cleanDirArg) {
|
||||||
|
await plugins.smartfile.fs.ensureEmptyDir(dirArg);
|
||||||
|
}
|
||||||
|
const collections = await this.getCollections();
|
||||||
|
for (const collection of collections) {
|
||||||
|
await this.dumpCollectionToDir(collection, dirArg, nameFunctionArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async dumpAllCollectionsToTarArchiveStream(
|
||||||
|
collectionArg: plugins.mongodb.Collection,
|
||||||
|
filePathArg: string
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user