vg-mongo
v2.0.0
Published
This is a MongoDB Client, based on mongodb package, with pagination support
Downloads
17
Maintainers
Readme
vg-mongo
Description
vg-mongo is a MongoDB client, based on the mongodb package, with pagination support. It offers a simplified interface for interacting with MongoDB, facilitating the implementation of common database functions.
Features
- Based on the official MongoDB package for Node.js.
- Integrated support for pagination.
- Facilitates access to collections and database operations.
Installation
To install vg-mongo, use npm:
npm install vg-mongo
Basic Usage
To start and use vg-mongo:
const vgMongo = require('vg-mongo');
// Database connection
const db = await vgMongo('mongodb://localhost:27017', 'myDatabase', { useNewUrlParser: true, useUnifiedTopology: true });
// Using a collection
const myCollection = db.myCollection;
// Closing the connection
await db.close();
Pagination Usage
The vg-mongo library includes an incorporated pagination function:
// Using pagination in a collection
const query = {}; // Your MongoDB query here
const fields = {}; // Specific fields you want to retrieve
const options = {
limit: 10, // Number of documents per page
page: 1, // Current page number
sort: { _id: 1 } // Sort by _id in ascending order
};
// Get the paginated documents
const paginatedResults = await myCollection.paginate(query, fields, options);
console.log(paginatedResults);
Details of the Paginate Function
query
: Search criteria in MongoDB.fields
: Fields to return in the documents.options
: Pagination parameters such aslimit
,page
, andsort
.
Tests
To run tests:
npm test
Contributions
Contributions are welcome. Please check the open issues for reporting bugs or suggesting improvements.
License
vg-mongo is under the ISC license.