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

xlsx-mongo

v1.0.15

Published

Streamlined Import, Export, and CRUD Operations between XLSX and MongoDB

Downloads

36

Readme

About The Project

Seamless Integration for Importing, Exporting, and Manipulating Data between XLSX and MongoDB.

Getting Started

  1. Make a mongodb database
  2. Copy the connection string of the database
  3. Paste the connection string in the .env file named MONGO_URL
  4. Check env_example file for more info - env_example
  5. Install the package
    npm install xlsx-mongo
  6. Require the package in your main file
const xlsxMongo = require('xlsx-mongo');

Functions

Init function is required to be run before any other function.

xlsxMongo.init(filePath);

Import data from excel file to the specified mongodb collection.

xlsxMongo.import(collectionName, showConsoleMessages);

Export data from the specified mongodb collection to excel file.

const exportFilePath = path.join(__dirname, 'Export.xlsx');
xlsx2mongo.export(collectionName, exportFilePath, showConsoleMessages)

Add data from excel file to the specified mongodb collection.

xlsxMongo.add(collectionName, filePath, showConsoleMessages);

Insert data to the specified mongodb collection.

const insertData = { 'Name': 'Kurizu', 'Address': 'poopy' };
xlsx2mongo.insert(collectionName, insertData, showConsoleMessages)

Delete data from the specified mongodb collection.

xlsxMongo.delete(collectionName, showConsoleMessages);

Update data from the specified mongodb collection.

xlsx2mongo.update(collectionName, updateCriteria, updateData, showConsoleMessages)

Find data from the specified mongodb collection.

xlsx2mongo.find(collectionName, findCriteria, showConsoleMessages)

Find data with projection from the specified mongodb collection.

const findCriteriaPro = { 'Name': 'Kurizu' };
const projection = { 'Name': 1 };
xlsx2mongo.findWithProjection(collectionName, findCriteriaPro, projection, showConsoleMessages)

Replace data with new excel file

const replaceFilePath = path.join(__dirname, 'Replace.xlsx');
xlsx2mongo.replace(collectionName, replaceFilePath, showConsoleMessages)

Check env_example file for more info - env_example

Usage

const xlsx2mongo = require('xlsx-mongo');
const mongoose = require('mongoose');
require('dotenv').config()
const path = require('path');

const filePath = path.join(__dirname, 'Test2.xlsx');
const showConsoleMessages = false;

xlsx2mongo.init(filePath);

const collectionName = 'test';

mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(async () => {
    
    // Import data from the Excel file to the specified collection
    xlsx2mongo.import(collectionName, showConsoleMessages).then(() => {
        mongoose.connection.close();
    });

    // // Add data from the Excel file to the specified collection
    xlsx2mongo.add(collectionName, filePath, showConsoleMessages).then(() => {
        mongoose.connection.close();
    });

    // Insert data to the specified collection
    const insertData = { 'Name': 'Kurizu', 'Address': 'poopy' };
    xlsx2mongo.insert(collectionName, insertData, showConsoleMessages).then(() => {
        mongoose.connection.close();
    });

    // Export data from the specified collection to the Excel file
    const exportFilePath = path.join(__dirname, 'Export.xlsx');
    xlsx2mongo.export(collectionName, exportFilePath, showConsoleMessages).then(() => {
      mongoose.connection.close();
    });

    // Delete data from the specified collection
    xlsx2mongo.delete(collectionName, showConsoleMessages).then(() => {
        mongoose.connection.close();
    });

    // Update data from the specified collection
    //  to update single row
    const updateCriteria = { 'Name': 'efrwdawd' };
    const updateData = { $set: { 'Name': 'John Doe' } };
    xlsx2mongo.update(collectionName, updateCriteria, updateData, showConsoleMessages).then(() => {
        mongoose.connection.close();
    }); 

    // to update multiple rows
    const updateCriteriaMultiple = { 'Name': 'dwgdrthg', 'Address': 'grgdrgd' };
    const updateDataMultiple = { $set: { 'Name': 'Kurizu', 'Address': 'poopy' } };
    xlsx2mongo.update(collectionName, updateCriteriaMultiple, updateDataMultiple, showConsoleMessages).then(() => {
        mongoose.connection.close();
    });

    // Find data from the specified collection
    const findCriteria = { 'Name': 'Kurizu' };   
    xlsx2mongo.find(collectionName, findCriteria, showConsoleMessages).then((res) => {
        console.log(res);
        mongoose.connection.close();
    });

    // Find data with projection
    const findCriteriaPro = { 'Name': 'Kurizu' };
    const projection = { 'Name': 1 };
    xlsx2mongo.findWithProjection(collectionName, findCriteriaPro, projection, showConsoleMessages).then((res) => {
        console.log(res);
        mongoose.connection.close();
    });

    // Replace data with new excel file
    const replaceFilePath = path.join(__dirname, 'Replace.xlsx');
    xlsx2mongo.replace(collectionName, replaceFilePath, showConsoleMessages).then(() => {
        mongoose.connection.close();
    });

    // Avoid running the above functions at the same time
})
.catch((err) => {
    console.error('Error:', err);
});

For more information on how to use it visit

If you want me to add more functions or have any issues with the package, feel free to contact me on discord kurizu.taz or open an issue on github.

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Package Made by: kurizu.taz on discord Github - https://github.com/crizmo/xlsx-mongo