Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@brickyang/easy-mongodb
Advanced tools
Readme
This lib base on node-mongodb-native, provides the official MongoDB native driver and APIs.
It wraps some frequently-used API to make it easy to use but keep all properties as it is. For example, to find a document you need this with official API
db.collection('name')
.find(query, options)
.skip(skip)
.limit(limit)
.project(project)
.sort(sort)
.toArray();
and with this lib
mongo.find('name', { query, skip, limit, project, sort, options });
If you are using Egg.js, please see egg-mongo-native.
npm install --save @brickyang/easy-mongodb
const config = {
host: 'host',
port: 'port',
name: 'test',
user: 'user',
password: 'password',
options: {},
};
// mongodb://host1:port1,host2:port2/name?replicaSet=test
const config = {
host: 'host1,host2',
port: 'port1,port2',
name: 'name',
options: { replicaSet: 'test' },
};
// mongodb://host:port1,host:port2/name?replicaSet=test
const config = {
host: 'host',
port: 'port1,port2',
name: 'name',
options: { replicaSet: 'test' },
};
The APIs provided by this lib usually need two arguments. The first is commonly the collection name, and the second is an object keeps the arguments of official API.
const MongoDB = require('@brickyang/easy-mongodb');
const mongo = new MongoDB(config);
// connection
mongo
.connect()
.then(client => {
// `client` is instance of connected MongoClient
})
.catch(error => {
// handle error
});
// or
mongo.on('connect', () => {
// do something
});
mongo.on('error', error => {
// handle error
});
// insert one doc
const args = { doc, options };
mongo.insertOne('collection', args);
// transaction
const session = mongo.startTransaction();
const args = { doc, { session } };
mongo.insertOne('collection1', args);
mongo.insertOne('collection2', args);
session.commitTransaction();
Until now, this plugin provides these functions:
You can always use mongo.db
and mongo.client
to use all official APIs. Check the
APIs here:
Node.js MongoDB Driver API.
function create(doc) {
mongo
.insertOne('name', { doc })
.then(result => console.log(result))
.catch(error => console.error(error));
}
async function create(doc) {
try {
const result = await mongo.insertOne('name', { doc });
console.log(result);
} catch (error) {
console.error(error);
}
}
If you use mongo.db
you could use callback(usually the last argument), but
this lib doesn't support callback because Promise and async/await are better.
FAQs
Based on MongoDB Native Node.js Driver.
The npm package @brickyang/easy-mongodb receives a total of 54 weekly downloads. As such, @brickyang/easy-mongodb popularity was classified as not popular.
We found that @brickyang/easy-mongodb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.