8 Commits

Author SHA1 Message Date
a75dca0771 1.0.8 2022-06-06 16:52:42 +02:00
47d006ce47 fix(core): update 2022-06-06 16:52:41 +02:00
fd0e4fc294 1.0.7 2022-06-06 16:22:58 +02:00
7d86f3382c fix(core): update 2022-06-06 16:22:58 +02:00
1dbbc1ecdb 1.0.6 2022-06-06 16:01:59 +02:00
931b4ce4fd fix(core): update 2022-06-06 16:01:59 +02:00
f4d2225766 1.0.5 2022-06-06 16:01:26 +02:00
2d2bb50578 fix(core): update 2022-06-06 16:01:25 +02:00
5 changed files with 41 additions and 17 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@pushrocks/mongodump",
"version": "1.0.4",
"version": "1.0.8",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@pushrocks/mongodump",
"version": "1.0.4",
"version": "1.0.8",
"license": "MIT",
"dependencies": {
"@pushrocks/lik": "^6.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@pushrocks/mongodump",
"version": "1.0.4",
"version": "1.0.8",
"private": false,
"description": "a tool to handle dumps of mongodb databases",
"main": "dist_ts/index.js",
@@ -10,7 +10,7 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)"
"build": "(tsbuild --web --allowimplicitany)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",

View File

@@ -27,10 +27,7 @@ tap.test('should add a mongotarget to mongodump instance', async () => {
tap.test('should dump a collection to a directory', async () => {
const target = await testMongodump.addMongoTargetByMongoDescriptor(await testSmartMongo.getMongoDescriptor());
const collections = await target.getCollections();
for (const collection of collections) {
await target.dumpCollectionToDir(collection, '.nogit', doc => doc.id);
}
await target.dumpAllCollectionsToDir('.nogit', docArg => docArg.id, true);
})
tap.test('should stop the smartmongo instance', async () => {

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/mongodump',
version: '1.0.4',
version: '1.0.8',
description: 'a tool to handle dumps of mongodb databases'
}

View File

@@ -5,9 +5,7 @@ import * as plugins from './mongodump.plugins.js';
* + exposes functions to interact with the dump target
*/
export class MongoDumpTarget {
public static async createAndInit(
mongoDescriptorArg: plugins.tsclass.database.IMongoDescriptor
) {
public static async createAndInit(mongoDescriptorArg: plugins.tsclass.database.IMongoDescriptor) {
const mongoDumpTarget = new MongoDumpTarget(mongoDescriptorArg);
await mongoDumpTarget.init();
return mongoDumpTarget;
@@ -61,19 +59,48 @@ export class MongoDumpTarget {
/**
* 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 collectionDir = plugins.path.join(dirPath, collectionArg.collectionName);
await plugins.smartfile.fs.ensureDir(collectionDir);
const cursor = collectionArg.find();
let value = await cursor.next();
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();
}
}
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
) {}
}