This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

mongoland
TypeScript icon, indicating that this package has built-in type declarations

4.4.1 • Public • Published

mongoland

  • mongoland is an superset of mongoose which makes it easier to connect to MongoDB and disconnect from it. also it has CRUD methods which makes it easier to create, read, update and delete data from MongoDB.

Installation

npm install mongoland@latest

Usage

const mongoland = require("mongoland"); // Importing the package

const Connector = new mongoland.Mongo({
    MongoURL: "Provide the URL",
    NeverDisconnect: "Provide true/false",
    Schema: "Provide the Schema Object",
    CollectionName: "Provide the Collection Name"
}); // Creating an instance of the Mongo class
  • Connector is an instance of the Mongo class

Connection Methods

Connector.Connect(); // Connects to MongoDB once and you can disconnect using Connector.disconnect()
Connector.disconnect(); // Disconnects from MongoDB if connected whenever you want (Only works when you pass NeverDisconnect as false in the constructor)

Find Methods

if you want to use CRUD methods, you have to provide the Schema in the constructor

Connector.find().then((data) => {
    console.log(data)
}) // Finds all the data in the database


Connector.find('AND', [{name: 'John'}]).then((data) => {
    console.log(data)
    output: [{name: 'John'}, {name: 'John'}, {name: 'John'}]
}) // Set the array of objects to find the data in the database with Specific Filter with AND operator

Connector.find('OR', [{name: 'John'}]).then((data) => {
    console.log(data)
    output: [{name: 'John'}, {name: 'John'}, {name: 'John'}]
}) // Set the array of objects to find the data in the database with Specific Filter with OR operator


Connector.find('AND',[{name: 'John'}], 1).then((data) => {
    console.log(data)
    output: [{name: 'John'}]
}) // Set the array of objects to find the data in the database with Specific Filter and Limit with AND operator

Connector.find('OR',[{name: 'John'}], 1).then((data) => {
    console.log(data)
    output: [{name: 'John'}]
}) // Set the array of objects to find the data in the database with Specific Filter and Limit with OR operator

Connector.findAndCount('AND', [{name: 'John'}]).then((data) => {
    console.log(data)
    output: {
        count: 3,
        data: [{name: 'John'}, {name: 'John'}, {name: 'John'}]
    }
}) // Set the array of objects to find the data in the database with Specific Filter and Count with AND operator

Connector.findAndCount('OR', [{name: 'John'}]).then((data) => {
    console.log(data)
    output: {
        count: 3,
        data: [{name: 'John'}, {name: 'John'}, {name: 'John'}]
    }
}) // Set the array of objects to find the data in the database with Specific Filter and Count with OR operator


Connector.findAndCount('AND', [{name: 'John'}], 1).then((data) => {
    console.log(data)
    output: {
        count: 1,
        data: [{name: 'John'}]
    }
}) // Set the array of objects to find the data in the database with Specific Filter, Count and Limit with AND operator

Connector.findAndCount('OR', [{name: 'John'}], 1).then((data) => {
    console.log(data)
    output: {
        count: 1,
        data: [{name: 'John'}]
    }
}) // Set the array of objects to find the data in the database with Specific Filter, Count and Limit with OR operator

You can also use the following filters for aggregation as per as Mongoose

Connector.find([{ age: { $lt: 20 } }, { age: { $gt: 12 } }]).then((data) => {
    console.log(data);
    output: [
        { age: 13 },
        { age: 14 },
        { age: 15 },
        { age: 16 },
        { age: 17 },
        { age: 18 },
        { age: 19 }
    ];
}); // Set the array of objects to find the data in the database with less than and greater than filter

Connector.find([{ age: { $lte: 20 } }, { age: { $gte: 12 } }]).then((data) => {
    console.log(data);
    output: [
        { age: 12 },
        { age: 13 },
        { age: 14 },
        { age: 15 },
        { age: 16 },
        { age: 17 },
        { age: 18 },
        { age: 19 },
        { age: 20 }
    ];
}); // Set the array of objects to find the data in the database with less than or equal to and greater than or equal to filter

Connector.find([{ age: { $lt: 20 } }, { age: { $gt: 12 } }], 1).then((data) => {
    console.log(data);
    output: [{ age: 13 }];
}); // Set the array of objects to find the data in the database with less than and greater than filter and Limit

Connector.findAndCount([{ age: { $lt: 20 } }, { age: { $gt: 12 } }], 1, 1).then(
    (data) => {
        console.log(data);
        output: {
            Skipped: 1,
            Limit: 1,
            count: 1,
            Data: [{ age: 13 }];
        }
    }
); // Set the array of objects to find the data in the database with less than and greater than filter, Limit with skip

Insert Methods

Connector.create({name: 'John'}).then((data) => {
    console.log(data)
    output: {
        status:true,
        message: "Successfully Created Data",
        NewCount: 1,
        NewData: [{name: 'John'}]
    }
}) // Creates a new document in the database

Connector.create({name:"Ankan Saha", Address:{ Street:"Address"}}).then((data) => {
    console.log(data)
    output: {
        status:true,
        message: "Successfully Created Data",
        NewCount: 1,
        NewData: [{name: 'Ankan Saha', Address:{ Street:"Address"}}]
    }
}) // Creates a new document in the database with nested objects

**Note: Make sure you provide the Right Schema in the constructor if you want to use the create method** 

Update Methods

Connector.update([{name: 'John'}], {name: 'John Doe'}, false).then((data) => {
    console.log(data)
    output: {
        status:true,
        message: "Successfully Updated Data",
        UpdatedCount: 1,
        UpdatedData: [{name: 'John Doe'}]
    }
}) // Updates the data in the database with multi option set to false

Connector.update([{name:"John"}], {$set:{"User.name":"John", "User.Surname":"Doe"}}, false).then((data) => {
    console.log(data)
    output: {
        status:true,
        message: "Successfully Updated Data",
        UpdatedCount: 1,
        UpdatedData: [{name: 'John', Surname: 'Doe'}]
    }
}) // Updates the data in the database with nested objects


Connector.update([{name: 'John'}], {name: 'John Doe'}, true).then((data) => {
    console.log(data)
    output: {
        status:true,
        message: "Successfully Updated Data",
        UpdatedCount: 5,
        UpdatedData: [{name: 'John Doe'}, {name: 'John Doe'}, {name: 'John Doe'}, {name: 'John Doe'}, {name: 'John Doe'}]
    }
}) // Updates the data in the database with multi option set to true

Delete Methods

Connector.delete([{name: 'John'}], false).then((data) => {
    console.log(data)
    output: {
        status:true,
        message: "Successfully Deleted Data",
        DeletedCount: 1,
        DeletedData: [{name: 'John'}]
    }
}) // Deletes the data in the database with multi option set to false

Connector.delete([{name: 'John'}], true).then((data) => {
    console.log(data)
    output: {
        status:true,
        message: "Successfully Deleted Data",
        DeletedCount: 5,
        NewData: [{name:"Ankan"}]
    }
}) // Deletes the data in the database with multi option set to true

Important:

  • If you Don't provide the URL, it will try to connect to the default URL: mongodb://localhost:27017 with log set to true.

Package Sidebar

Install

npm i mongoland

Weekly Downloads

1

Version

4.4.1

License

MIT

Unpacked Size

85.8 kB

Total Files

44

Last publish

Collaborators

  • theankansaha