![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
mongo-baseops
Advanced tools
Creates an object with base database operations which can then be extended and overridden as required for each collection.
the goal of this class is create a base object that has the basic required methods for average database collection which can be quickly modified and exported for each collection.
//address database ops index.js file
const BaseDatabaseOps = require("path/to/this/class")
class AddressDB extends BaseDatabaseOps {
constructor() {
super('address')
}
}
exports = module.exports = AddressDB
and as the required methods are already implemented in this base class it will take care of them such as writeOne, writeMany, readOne, readMany, list, updateOne, updateMany, removeOne, removeMany.
And if we ever need to change a method we can just override it.
For example let's say we want our readOne
so that we can resolve/populate the customer field with customer info from the customer
collection if required. Here is how we would approach the implementation:
//address database ops index.js file
const BaseDatabaseOps = require("path/to/this/class")
class AddressDB extends BaseDatabaseOps {
constructor() {
super('address')
}
//example for overriding method
async function readOne(id, resolve = {}) {
const aggregatePipeline = [];
aggregatePipeline.push({
$match: {
_id: { $in: id.map(i => new client.ObjectID(i)) }
}
})
if(resolve.customer){
aggregatePipeline.push({
$lookup: {
from: "customer",
localField: "customer",
foreignField: "_id",
as: "customer"
}
},
{
$unwind: {
path: "$customer",
preserveNullAndEmptyArrays: true
}
}
)
}
const db = await this.getDB();
const result = await db.collection("address").aggregate(aggregatePipeline).toArray();
return result;
}
}
exports = module.exports = AddressDB
string
- name of the database collectionEven though the base
readOne
,readMany
method supportsresolve
parameter, it won't respond to them. If resolving in needed for any collection than it should be implemented by overriding the base methods. A warning will be printed on the console every time any property is passed in theresolve
param.
Even though the base
list
method supportsresolve
andfilter
parameter, it won't respond to them. If filtering and resolving in needed for any collection than it should be implemented by overriding the base methods. A warning will be printed on the console every time any property is passed in thefilter
orresolve
param.
getDB(): Promise< object: databaseInstance >
getCollection( ): Promise< object: dbCollectionInstance >
getClient(): Promise< object: databaseClientInstance >
writeOne( entity:object ) : Promise< object >
writeMany( entityList: Array<object> ) : Promise< Array<object> >
updateOne( id: string, entity: object ) : Promise< object >
updateMany( entityList: Array<object> ) : Promise< Array<object> >
readOne( id: string, entity: object ) : Promise< object >
readMany( id: string, resolve: object ) : Promise< Array<object> >
list( filter?: object, resolve?: object, paginateOptions?: object) : Promise< Array<object> >
removeMany(id: string): Promise< object >
removeOne(idList: Array<string>): Promise< Array<object> >
FAQs
mongo db database baseops
The npm package mongo-baseops receives a total of 3 weekly downloads. As such, mongo-baseops popularity was classified as not popular.
We found that mongo-baseops demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.