Socket
Socket
Sign inDemoInstall

@developedbyant/mongodb

Package Overview
Dependencies
158
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @developedbyant/mongodb

All functions return false or result, alway check to see if returned value is not false. ``` javascript // IMPORT MONGODB CLASS (MODULE) import Mongodb from "@anthony16t/mongodb";


Version published
Maintainers
1
Created

Readme

Source

Mongodb module, make to be simple a fast to use

All functions return false or result, alway check to see if returned value is not false.

// IMPORT MONGODB CLASS (MODULE)
import Mongodb from "@anthony16t/mongodb";

// SET A VARIABLE DB FOR DATABASE
const db = new Mongodb('test')

// CONNECT TO DATABASE
// ALWAY CONNECT TO DATABASE BEFORE RUNNING ANY FUNCTIONS INSIDE MONGODB
await db.connect()

// DROP DATABASE
await db.dropDatabase('test')

// GET A LIST A ALL DATABASES
const databases = await db.listDatabases()

// GET A LIST OF ALL COLLECTIONS IN CURRENT DATABASE
const collections = await db.listCollections()

// DROP COLLECTION
await db.dropCollection('users')

// GET A LIST OF DISTINCT KEYS FROM COLLECTION
const distinctList = await db.distinct('collectionName','name')

// FIND ONE OBJECT FROM COLLECTION
const user = await db.findOne('collectionName')

// UPDATE ONE OBJECT FROM COLLECTION
await db.updateOne('collectionName',{name:"tony"},{pro:true})

// DELETE ONE OBJECT FROM COLLECTION
await db.deleteOne('collectionName',{name:"tony"})

// INSERT ONE JSON DOCUMENT TO COLLECTION
const insertedUser = await db.insertOne('collectionName',{name:"tony",age:23})

// FIND MULTIPLE OBJECTS FROM COLLECTION
const users = await db.find({age:{$gte:21}}).toArray()

// INSERT MULTIPLE OBJECTS TO COLLECTION
await db.insertMany('collectionName',[{name:"jon"},{name:"tom"}])

// UPDATE MULTIPLE OBJECTS IN COLLECTION
await db.updateMany('collectionName',{},{testValue:"hi"})

// DELETE MULTIPLE OBJECTS IN COLLECTION
await db.deleteMany('collectionName',{status:"ban"})

// RUN MONGODB AGGREGATE
const usersA = await db.aggregate([{
    $match:{name:"kiara"}
}]).toArray()

// CLOSE DATABASE CONNECTION, NO NEEDED BUT HERE JUST INCASE YOU NEED IT
await db.close()

------- MODULE NOT FINISHED YET -------

Keywords

FAQs

Last updated on 29 Aug 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc