pxl-mongodb
v1.0.0
Published
Access counting for any Express-served url - e.g. for a tracking pixel in emails
Downloads
122
Maintainers
Readme
pxl-mongodb
Access counting for any Express-served url - e.g. for a tracking pixel in emails
Overview
pxl-mongodb
is an extension of the pxl
library that adds a persistence layer for mongoDB.
Please check out the README of the pxl
library and then come back for instructions on installing and using this library.
Installation
This is a module for node.js and is installed via npm:
npm install pxl-mongodb --save
pxl
is installed automatically with pxl-mongodb
.
Usage
Everything described in the README of the pxl
library is relevant for pxl-mongodb
as well. The only difference is that this library includes a persistence layer for mongoDB and needs to be initialized differently.
let PxlMongodb = require('pxl-mongodb')
let pxl = new PxlMongodb({
// Options described for the pxl lib like queryParam and logPxlFailed can be passed here as well
// Additional options are:
collectionPxls: 'pxls', // Name of the collection to store pxl documents for access tracking
collectionLinks: 'links', // Name of the collection to store shortened links
alwaysShortenWithNewLinkId: false // Set to true if you need a different linkId each time you shorten a link - even if the link was shortened before
// Omit the options to use the default values equal to the example values above
})
Before you use any functions like pxl.createdPxl(...)
you need to connect to the database:
pxl.connect('mongodb://localhost:27017/test', {}) // Passed values are the defaults
.then((collections) => {
// Returns the collections to allow creating additional indexes etc.
collections.pxls.count().then(console.log)
collections.lists.count().then(console.log)
})
- First parameter
uri
: The mongoDB connection string that is used to connect to the database using themongodb
library - Second parameter
connectionOptions
: Additional options to configure the connection. For details see themongodb
API docs. - Returns a promise with the collection objects as shown above. For details see the
mongodb
API docs.
And finally:
pxl.disconnect()
.then(() => {
console.log('Database connection is closed')
})
Contributing
To set up your development environment for pxl-mongodb
:
- Clone this repo to your desktop,
- in the shell
cd
to the main folder, - hit
npm install
, - run
npm run dev
.
npm run dev
watches all source files and if you save some changes it will execute all tests. The test coverage report can be viewed from ./coverage/lcov-report/index.html
.
If you want to debug a test you should use npm run test-debug
to run all tests without obscuring the code by the test coverage instrumentation.
Change History
- v1.0.0 (2024-05-13)
- Breaking Change: Upgraded to
mongodb
versions5.x
or6.x
- Breaking Change: Supporting node.js version
>=14.20.1
- Breaking Change: Upgraded to
- v0.0.7 (2020-09-17)
- Storing links with
writeConcern: { w: 'majority' }
- Updated dependencies
- Storing links with
- v0.0.6 (2020-06-06)
- Updated dependencies to fix security vulnerabilities
- Added node v8 and v10 to ci build
- Storing pixels with
writeConcern: { w: 'majority' }
- v0.0.5 (2018-04-12)
- Using latest pxl version which debounces pxl logging when a user double clicks
- Breaking Change: If you call
.logPxl(...)
directly instead of using thetrackPxl
middleware then.logPxl(...)
calls which get debounced resolve toundefined
.
- v0.0.4 (2016-10-08)
- Fixed unshorting links
- Added index to speed up checking for already shortened links
- v0.0.3 (2016-10-08)
- Per default, the same links will (almost always) get the same linkId when shortened
- Wiring to support referenced pxls
- Upgraded to
[email protected]
- v0.0.2 (2016-10-06)
- Upgraded to
[email protected]
- Upgraded to
- v0.0.1 (2016-10-06)
- Initial version
License (ISC)
In case you never heard about the ISC license it is functionally equivalent to the MIT license.
See the LICENSE file for details.