@froice/mongoconnector
v1.6.1
Published
A simple mongo db connector. For use in microservices.
Downloads
30
Readme
Froice Mongo Connector
Install
npm install @froice/mongoconnector
Usage
Create a document
const config = {
mongoURL: ["localhost:27017"],
mongoUsername: "user",
mongoPassword: "Password123",
mongoDatabase: "userAuthenticationDatabase",
mongoAuth: true,
mongoAuthSource: "userAuthenticationDatabase"
}
const mc = new MongoConnector(config);
mc.create('user', {
username: "abc",
password: "def",
groups: []
}).then(done => {
// Do stuff
});
Update a document
const config = {
mongoURL: ["localhost:27017"],
mongoUsername: "user",
mongoPassword: "Password123",
mongoDatabase: "userAuthenticationDatabase",
mongoAuth: true,
mongoAuthSource: "userAuthenticationDatabase"
}
const mc = new MongoConnector(config);
mc.update('user', {
username: "abc"
}, {
$addToSet: {
groups: "def"
}
}).then(done => {
// Do stuff
});
Find a document
const config = {
mongoURL: ["localhost:27017"],
mongoUsername: "user",
mongoPassword: "Password123",
mongoDatabase: "userAuthenticationDatabase",
mongoAuth: true,
mongoAuthSource: "userAuthenticationDatabase"
}
const mc = new MongoConnector(config);
mc.find('user', {
username: "abc"
}).then(users => {
// Do stuff
});
Delete a document
const config = {
mongoURL: ["localhost:27017"],
mongoUsername: "user",
mongoPassword: "Password123",
mongoDatabase: "userAuthenticationDatabase",
mongoAuth: true,
mongoAuthSource: "userAuthenticationDatabase"
}
const mc = new MongoConnector(config);
mc.delete('user', {
username: "abc"
}).then(done => {
// Do stuff
});