Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crizmo/xlsx-mongo
Streamlined Import, Export, and CRUD Operations between XLSX and MongoDB
https://github.com/crizmo/xlsx-mongo
add crud delete excel export find import mongodb update xlsx
Last synced: 13 days ago
JSON representation
Streamlined Import, Export, and CRUD Operations between XLSX and MongoDB
- Host: GitHub
- URL: https://github.com/crizmo/xlsx-mongo
- Owner: crizmo
- License: mit
- Created: 2023-07-07T07:06:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-22T13:33:48.000Z (over 1 year ago)
- Last Synced: 2024-12-15T03:03:18.993Z (19 days ago)
- Topics: add, crud, delete, excel, export, find, import, mongodb, update, xlsx
- Language: JavaScript
- Homepage: https://xlsx-mongo.vercel.app/
- Size: 82 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
XLSX-Mongo
Streamlined Import, Export, and CRUD Operations between XLSX and MongoDB
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
## About The ProjectSeamless 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
```sh
npm install xlsx-mongo
```
6. Require the package in your main file
```JS
const xlsxMongo = require('xlsx-mongo');
```## Functions
Init function is required to be run before any other function.
```javascript
xlsxMongo.init(filePath);
```Import data from excel file to the specified mongodb collection.
```javascript
xlsxMongo.import(collectionName, showConsoleMessages);
```Export data from the specified mongodb collection to excel file.
```javascript
const exportFilePath = path.join(__dirname, 'Export.xlsx');
xlsx2mongo.export(collectionName, exportFilePath, showConsoleMessages)
```Add data from excel file to the specified mongodb collection.
```javascript
xlsxMongo.add(collectionName, filePath, showConsoleMessages);
```Insert data to the specified mongodb collection.
```javascript
const insertData = { 'Name': 'Kurizu', 'Address': 'poopy' };
xlsx2mongo.insert(collectionName, insertData, showConsoleMessages)
```Delete data from the specified mongodb collection.
```javascript
xlsxMongo.delete(collectionName, showConsoleMessages);
```Update data from the specified mongodb collection.
```javascript
xlsx2mongo.update(collectionName, updateCriteria, updateData, showConsoleMessages)
```Find data from the specified mongodb collection.
```javascript
xlsx2mongo.find(collectionName, findCriteria, showConsoleMessages)
```Find data with projection from the specified mongodb collection.
```javascript
const findCriteriaPro = { 'Name': 'Kurizu' };
const projection = { 'Name': 1 };
xlsx2mongo.findWithProjection(collectionName, findCriteriaPro, projection, showConsoleMessages)
```Replace data with new excel file
```javascript
const replaceFilePath = path.join(__dirname, 'Replace.xlsx');
xlsx2mongo.replace(collectionName, replaceFilePath, showConsoleMessages)
```Check env_example file for more info - env_example
## Usage
```javascript
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
- [Github](https://github.com/crizmo/xlsx-mongo)
- [Example](https://github.com/crizmo/xlsx-mongo/tree/main/tests)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](https://github.com/crizmo/xlsx-mongo)