1.5.7 • Published 2 years ago

mongoose-truck v1.5.7

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

mongoose-truck 🚚

mongoose-truck is a Node.js package for handling with data transaction between different MongoDb clusters.

Terms

  • Source connection is the main database which will provide us data basically
  • Destination connections are the databases in which we are going to insert the data

Definitions

.create(conn1,conn2,conn3)

  • conn1 - source connection
  • conn2 - destination connection
  • conn3 - destination connection

.loadFrom() object:

model       // preferred model name
schema      // Schema for the collection - reading the data
query:      // Query for searching over the collection
populate:   // Relation with other collections - Same with .populate() method
skip:       // skipping N values in the collection - same with .skip() method
sort:       // sorting - same with .sort() method
select:     // selecting keys - same with .select()
concurrent: // concurrent adjusts the pagination fetching constant
limit:      // total data will be fetched - same with .limit() method

.emptyTo() object:

model       // preferred model name
schema      // Schema for the collection to load the data

.start() object:

parse: //if true this will return the datas added into cluster and if false returns empty array

Installation

Use the package manager npm to install mongoose-truck.

npm i mongoose-truck

How to use

const MongooseTruck = require("mongoose-truck")

Managing the Connections

const conn1 = await MongooseTruck.connect("database_connection_string"),
        conn2 = await MongooseTruck.connect("database_connection_string"),
        conn3 = await MongooseTruck.connect("database_connection_string");

Reading from one collection Schema with one configuration.

const parsedData = await MongooseTruck.create(conn1, [conn2, conn3]).loadFrom({
    model: 'People',
    schema: PeopleSchema,
    query: {
        name: "John"
    },
    populate: {
        path: 'stars'
    },
    skip: 0,
    sort: {
        _id: -1
    },
    select: "_id name surname age",
    concurrent: 20,
    limit: 100
}).emptyTo({
    model: 'People',
    schema: PeopleSchema
}).start({
    parse: true
})

console.log(parsedData);

Reading from array of collections and Schemas with different configurations.

const parsedData = await MongooseTruck.create(conn1, [conn2, conn3]).loadFrom([{
        model: 'People',
        schema: PeopleSchema,
        query: {
            name: "John"
        },
        skip: 0,
        sort: {
            _id: -1
        },
        concurrent: 5,
        limit: 10
    },
    {
        model: 'People',
        schema: PeopleSchema,
        query: {
            name: "Adam"
        },
        populate: {
            path: 'stars'
        },
        skip: 1,
        sort: {
            _id: -1
        },
        select: "_id name surname age",
        concurrent: 3,
        limit: 20
    }
]).emptyTo({
    model: 'PersonsTests',
    schema: Person
}).start({
    parse: true
})
console.log(parsedData);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

1.5.7

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago