homevilla
homevilla

Reputation: 23

How to configure IP access in MongoDB atlas cluster though API or shell command?

How to configure IP access in MongoDB atlas cluster though API or shell command ?

It's very time consuming to configure IP access to MongoDB atlas cluster though MongoDB GUI web platform each time.

It'd be very easy if we have some option to add IP to access MongoDB atlas cluster though some API or some Mongo shell command, so how to achieve that?

mongodb atlas network access section

Upvotes: 0

Views: 956

Answers (2)

rickenbacker
rickenbacker

Reputation: 91

Here is current answer for CLI (to set up your current IP) - cli version is 1.7.3:

Docs: https://www.mongodb.com/docs/atlas/cli/stable/command/atlas-accessLists-create/

CLI call:

atlas accessList create --currentIp --type ipAddress --projectId $MONGO_ATLAS_PROJECT_ID --comment "Opening Network Access" --deleteAfter $EXPIRATON --output json

You need to provide only 2 parameters (except credentials of course):

MONGO_ATLAS_PROJECT_ID - ID of Your Mongo Atlas Project

EXPIRATON - Network Access expiration time in ISO-8601 format

This "--deleteAfter" parameter set by EXPIRATON var (considering You want your access to expire after some time) should be set in below format (based on linux date command):

date +%Y-%m-%dT%H:%M:%S%z  ->  2023-09-23T08:14:16+0100

So when you want for it to expire after for example 15 minutes, it should be set like this:

EXPIRATION=$(date -d '+15minutes' +%Y-%m-%dT%H:%M:%S%z)

Upvotes: 2

Dror
Dror

Reputation: 5505

The API documentation - for managing the access list: https://docs.atlas.mongodb.com/reference/api/access-lists/

Upvotes: 1

Related Questions