Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
a75dca0771 | |||
47d006ce47 | |||
fd0e4fc294 | |||
7d86f3382c | |||
1dbbc1ecdb | |||
931b4ce4fd | |||
f4d2225766 | |||
2d2bb50578 | |||
a877616739 | |||
377177bbbe | |||
35586691f1 | |||
32d3ea4d65 |
10
package-lock.json
generated
10
package-lock.json
generated
@@ -1,16 +1,18 @@
|
||||
{
|
||||
"name": "@pushrocks/mongodump",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.8",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@pushrocks/mongodump",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.8",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
"@pushrocks/smartfile": "^9.0.6",
|
||||
"@pushrocks/smartjson": "^4.0.6",
|
||||
"@pushrocks/smartpath": "^5.0.5",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@tsclass/tsclass": "^4.0.3",
|
||||
"mongodb": "^4.6.0"
|
||||
@@ -686,7 +688,6 @@
|
||||
"version": "5.0.5",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpath/-/smartpath-5.0.5.tgz",
|
||||
"integrity": "sha512-t2lXXGMpKnPlwubIcYGD6cGi2CUJxJ3t2yftVt8tHfjX68jELA5sJhFMtyD3AeFZVxePFZOCiHwWEbWkSDNnmw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@pushrocks/smartpdf": {
|
||||
@@ -6944,8 +6945,7 @@
|
||||
"@pushrocks/smartpath": {
|
||||
"version": "5.0.5",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpath/-/smartpath-5.0.5.tgz",
|
||||
"integrity": "sha512-t2lXXGMpKnPlwubIcYGD6cGi2CUJxJ3t2yftVt8tHfjX68jELA5sJhFMtyD3AeFZVxePFZOCiHwWEbWkSDNnmw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-t2lXXGMpKnPlwubIcYGD6cGi2CUJxJ3t2yftVt8tHfjX68jELA5sJhFMtyD3AeFZVxePFZOCiHwWEbWkSDNnmw=="
|
||||
},
|
||||
"@pushrocks/smartpdf": {
|
||||
"version": "3.0.2",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/mongodump",
|
||||
"version": "1.0.2",
|
||||
"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",
|
||||
@@ -39,6 +39,8 @@
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
"@pushrocks/smartfile": "^9.0.6",
|
||||
"@pushrocks/smartjson": "^4.0.6",
|
||||
"@pushrocks/smartpath": "^5.0.5",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@tsclass/tsclass": "^4.0.3",
|
||||
"mongodb": "^4.6.0"
|
||||
|
@@ -19,7 +19,22 @@ export const generateTestData = async (mongoDescriptorArg: smartdata.IMongoDescr
|
||||
@smartdata.svDb()
|
||||
data = {
|
||||
'some' : {
|
||||
'complex': 'structure'
|
||||
'complex': 'structure',
|
||||
more: 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@smartdata.Collection(db)
|
||||
class Truck extends smartdata.SmartDataDbDoc<Truck, Truck> {
|
||||
@smartdata.unI()
|
||||
id = `hello-${counter}`;
|
||||
|
||||
@smartdata.svDb()
|
||||
data = {
|
||||
'some' : {
|
||||
'complex': 'structure',
|
||||
more: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +42,8 @@ export const generateTestData = async (mongoDescriptorArg: smartdata.IMongoDescr
|
||||
while (counter < 100) {
|
||||
const house = new House();
|
||||
await house.save();
|
||||
const truck = new Truck();
|
||||
await truck.save();
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,11 @@ tap.test('should deploy sample data', async () => {
|
||||
tap.test('should add a mongotarget to mongodump instance', async () => {
|
||||
const target = await testMongodump.addMongoTargetByMongoDescriptor(await testSmartMongo.getMongoDescriptor());
|
||||
await target.getCollections();
|
||||
});
|
||||
|
||||
tap.test('should dump a collection to a directory', async () => {
|
||||
const target = await testMongodump.addMongoTargetByMongoDescriptor(await testSmartMongo.getMongoDescriptor());
|
||||
await target.dumpAllCollectionsToDir('.nogit', docArg => docArg.id, true);
|
||||
})
|
||||
|
||||
tap.test('should stop the smartmongo instance', async () => {
|
||||
|
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/mongodump',
|
||||
version: '1.0.2',
|
||||
version: '1.0.8',
|
||||
description: 'a tool to handle dumps of mongodb databases'
|
||||
}
|
||||
|
@@ -1,2 +1,3 @@
|
||||
export * from './mongodb.classes.mongodump.js';
|
||||
export * from './mongodb.classes.mongodumptarget.js';
|
||||
export * from './mongodump.classes.mongodump.js';
|
||||
export * from './mongodump.classes.mongodumptarget.js';
|
||||
|
||||
|
@@ -6,5 +6,5 @@ import * as plugins from './mongodump.plugins.js';
|
||||
*
|
||||
*/
|
||||
export class MongoCompressedDump {
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import * as plugins from './mongodump.plugins.js';
|
||||
import { MongoDumpTarget } from './mongodb.classes.mongodumptarget.js';
|
||||
import { MongoDumpTarget } from './mongodump.classes.mongodumptarget.js';
|
||||
|
||||
export class MongoDump {
|
||||
public mongoTargetObjectMap = new plugins.lik.ObjectMap<MongoDumpTarget>();
|
@@ -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,11 +59,48 @@ export class MongoDumpTarget {
|
||||
/**
|
||||
* dumps a collection to a directory
|
||||
*/
|
||||
public async dumpCollectionToDir(collectionArg: plugins.mongodb.Collection, dirArg: string) {
|
||||
|
||||
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`)
|
||||
);
|
||||
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
|
||||
) {}
|
||||
}
|
@@ -1,11 +1,22 @@
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
path
|
||||
}
|
||||
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartjson from '@pushrocks/smartjson';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartfile,
|
||||
smartjson,
|
||||
smartpath,
|
||||
smartpromise
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user