Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/digen21/dmxdev-mongoose-batch-write
Writing bulk operation in chunks
https://github.com/digen21/dmxdev-mongoose-batch-write
batch mongoose typescript utility-function
Last synced: 3 days ago
JSON representation
Writing bulk operation in chunks
- Host: GitHub
- URL: https://github.com/digen21/dmxdev-mongoose-batch-write
- Owner: digen21
- License: mit
- Created: 2024-12-22T12:02:25.000Z (17 days ago)
- Default Branch: main
- Last Pushed: 2024-12-22T12:03:48.000Z (17 days ago)
- Last Synced: 2024-12-22T13:18:55.675Z (17 days ago)
- Topics: batch, mongoose, typescript, utility-function
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@dmxdev/mongoose-batch-write
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mongoose Batch Write
This package provides a utility function to perform bulk write operations in chunks using Mongoose.
## Installation
```bash
npm install @dmxdev/mongoose-batch-write
```## Usage
```typescript
import bulkWriteInChunks from '@dmxdev/mongoose-batch-write';
import { Model } from 'mongoose';const model: Model = // initialize your Mongoose model
const documents = [
{
updateOne: {
filter: { username: doc.username }, // You can filter based on any field
update: { $set: doc }, // Update with the entire document
upsert: true, // Ensure upsert operation
},
},
// more bulk write operations
];
const chunkSize = 100; // specify the chunk size
const options = { ordered: false }; // specify bulk write optionsbulkWriteInChunks(model, documents, chunkSize, options)
.then(results => {
console.log('Bulk write results:', results);
})
.catch(error => {
console.error('Bulk write error:', error);
});
```## License
MIT