arch-mongodb-wrapper

This is a mongodb wrapper for simplify the data operations

Usage no npm install needed!

<script type="module">
  import archMongodbWrapper from 'https://cdn.skypack.dev/arch-mongodb-wrapper';
</script>

README

Arch-MongoDb-Wrapper

This is the ArchOffice MongoDb Wrapper to make easy create any MongoDb transactions

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

This package needs has the MongoDb official package.

var wrapper = require("./easymongodb")
// The last parameter is the auto-disconnect, it is true by default, if you set it as false, you 
// must use disconnect manually (using disconnect method).
var db = wrapper("<your url, ex: localhost>","<your-database>","27017","database-username","database-pwd",true);

// IMPORTANT: for all samples below the text "user" represent the mongodb collection

// To insert one field
db.insertOne({"name":"Charles", "pwd":"888888"},"user",function(err,data){
    console.log((err?"erro":"foi"));
});

// To delete by mongodb Id
db.deleteById("5c60c87abfad976e1b107a0f","user",function(err,data){
    console.log((err?"erro":"foi"));
});

// To delete by mongodb query
db.deleteByQuery({"name":"carlos"},"user",function(err,data){
    console.log((err?"erro":"foi"));
});

// To get all fields
db.getAll("user",function(err,data){
    console.log(data.result);
    return;
});

db.getById("5c60c883a559946e1cf19b7b","user",function(err,data){
    console.log(data.result);

    //if the auto disconnect is false, you can use the same connection for many operations and close one time
    db.disconnect();
    return;
});

db.getByQuery({"pwd":"999999"},"user",function(err,data){
    console.log(data.result);
    return;
});

db.insertOne({"name":"Paul", "pwd":"67676767"},"user",function(err,data){
    data.deleteByQuery({"name":"Jhow Martine", "pwd":"67676767"},"user",function(err,data){
        data.getAll("user",function(err,data){
            console.log(data.result);
            return;
        });
    });
});

db.updateByQuery({name:"Steve"},{ $set: {pwd: "xxxxxxxxZZZZwwWWW" }},"user",function(err,data){
    db.getAll("user",function(err,data){
        console.log(data.result);
        return;
    });
});

Installing

npm i arch-mongodb-wrapper -s

Authors

  • ArcHOffice Technology - By Carlos Pisani - PurpleBooth

Keywords

mongodb wrapper