1.1.62 • Published 4 months ago

connect2mongodb v1.1.62

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Installation:-

npm i connect2mongodb

Warning:-

Make sure you must have installed exact same version i.e.:- mongoose@8.12.1, in NextJS/Express Server.

npm i mongoose@8.12.1

Otherwise it will connect to the DB, but starts giving error while trying to access the DB.

How to use:-

Method 1:- With A Fixed Database:-

Firstly update your .env:-

Your MONGODB_URI will look like this:- mongodb+srv://username:password@hostname/your_database_name

MONGODB_URI=mongodb+srv://username:password@hostname/your_database_name

This module will atuomatically fetch your MONGODB_URI from the .env, but make sure to use the same/default format provided by MongoDB, and make sure to add the database name too.

Import the module:-

import { connect2MongoDB, disconnect2MongoDB } from 'connect2mongodb'

To Connect:-

await connect2MongoDB();

To Disconnect:-

await disconnect2MongoDB();

To Connect with a return value:-

This will return true if Connected to the database else false.

const customVariable = await connect2MongoDB();
console.log(customVariable);

To Disconnect with a return value:-

This will return true after Disconnecting to the database.

const customVariable = await disconnect2MongoDB()
console.log(customVariable);

Method 2:- With a dynamic database:-

Firstly update your .env:-

Your MONGO_URI will look like this:- mongodb+srv://username:password@host_name/

MONGO_URI=mongodb+srv://username:password@hostname/

This module will atuomatically fetch your MONGO_URI from the .env, but make sure to use the same format, and don't add the database name after last '/'.

Import the module:-

import { connect2MongoDB, disconnect2MongoDB } from 'connect2mongodb'

To Connect:-

await connect2MongoDB('Your Database Name');

To Disconnect:-

await disconnect2MongoDB();

To Connect with a return value:-

This will return true if Connected to the database else false.

const customVariable = await connect2MongoDB('Your Database Name');
console.log(customVariable);

To Disconnect with a return value:-

This will return true after Disconnecting to the database.

const customVariable = await disconnect2MongoDB()
console.log(customVariable);
1.1.62

4 months ago

1.1.61

4 months ago

1.1.60

4 months ago

1.1.59

5 months ago

1.1.58

5 months ago

1.1.57

5 months ago

1.1.56

6 months ago

1.1.55

6 months ago

1.1.54

6 months ago

1.1.52

6 months ago

1.1.53

6 months ago

1.1.51

7 months ago

1.1.50

7 months ago

1.1.49

7 months ago

1.1.48

7 months ago

1.1.47

8 months ago

1.1.46

8 months ago

1.1.45

8 months ago

1.1.44

8 months ago

1.1.38

10 months ago

1.1.37

10 months ago

1.1.39

10 months ago

1.1.41

9 months ago

1.1.40

9 months ago

1.1.43

9 months ago

1.1.42

9 months ago

1.1.36

10 months ago

1.1.35

11 months ago

1.1.34

11 months ago

1.1.29

1 year ago

1.1.28

1 year ago

1.1.30

1 year ago

1.1.33

12 months ago

1.1.32

12 months ago

1.1.31

12 months ago

1.1.27

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.0

1 year ago

1.1.10

1 year ago

1.1.0-beta.0

1 year ago

1.0.9

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

0.3.11

2 years ago

1.0.3

2 years ago

1.0.6-beta.4

2 years ago

1.0.6-beta.1

2 years ago

1.0.5-beta.1

2 years ago

1.0.6-beta.0

2 years ago

1.0.5-beta.2

2 years ago

1.0.6-beta.3

2 years ago

1.0.6-beta.2

2 years ago

1.0.5-beta.0

2 years ago

1.0.4-beta.0

2 years ago

1.0.3-beta.0

2 years ago

1.0.2-beta.0

2 years ago

1.0.0-beta.0

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.6

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

1.1.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.0

2 years ago