npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-truck

v1.5.7

Published

Node.js library for handling CRUD operations for different mongodb databases.

Downloads

63

Readme

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