can i use supabase filesystem with a nosql database?

can i use supabase filesystem with a nosql database?
93 Replies
Olyno
Olyno3y ago
Hi :vmathi: Do you mean the storage when saying "filesystem"?
LeBruno James
LeBruno JamesOP3y ago
hey, yes i do i ve got a project and i need storage but im using mongodb
Olyno
Olyno3y ago
You can use the Supabase storage, but i think you would need to serve files from a server
Olyno
Olyno3y ago
Supabase's storage doesn't give you a link directly, so you need to generate it. Example here: https://supabase.com/docs/guides/with-react#create-an-upload-widget
Supabase Documentation
Quickstart: React
Learn how to use Supabase in your React App.
LeBruno James
LeBruno JamesOP3y ago
so when i get the route of the image in the user device i need to send it to the backend and then store it there? thanks
Olyno
Olyno3y ago
Basically your website will request the url of the file to a specific server, which will be connected to Supabase and generate it. Here is a simple example for an avatar file (from the link above):
const { data, error } = await supabase.storage.from('avatars').download(path)

if (error) {
throw error
}

const url = URL.createObjectURL(data)
setAvatarUrl(url)
const { data, error } = await supabase.storage.from('avatars').download(path)

if (error) {
throw error
}

const url = URL.createObjectURL(data)
setAvatarUrl(url)
You don't need a server if you're using Supabase on a client side tho
LeBruno James
LeBruno JamesOP3y ago
oh ok ok, and is there any documentation to use supabase on the server side?
Olyno
Olyno3y ago
To make it simple, if you only want a "micro service" for storage, you will need a server to make the bridge between Supabase files and your clients/platforms. Otherwise, you can do it directly using Supabase SDKs 😄
LeBruno James
LeBruno JamesOP3y ago
yeah... but i already have the server coded
Olyno
Olyno3y ago
SDK + service role basically. It's the same stuff than the client side
LeBruno James
LeBruno JamesOP3y ago
oh ok so basically doing the same as the front end but sending the url to the server and doing it from the server, thanks man one more question, how do i create a bucket, it says i need postgresql
Olyno
Olyno3y ago
Supabase uses postgres under the hood
Olyno
Olyno3y ago
https://supabase.com/docs/reference/javascript/storage-createbucket It should not be harder than that. Do you have specific errors?
Supabase Documentation
createBucket()
createBucket()
LeBruno James
LeBruno JamesOP3y ago
i dont know, im kind of lost because i ve never used storage and im using mongodb
Olyno
Olyno3y ago
This should be the architecture you have
No description
Olyno
Olyno3y ago
Supabase and Mongo should not interact directly. The server should do the job
LeBruno James
LeBruno JamesOP3y ago
oh ok ok thanks and sorry for being so annoying
Olyno
Olyno3y ago
No problem! Don't hesitate to ping me again if need help :p
LeBruno James
LeBruno JamesOP3y ago
hey man, just started reading the docs and im not sure if i'm getting it, i think i have to follow this steps: 1 create a project and a bucket 2 create client with the supabase javascript module, even though im going to use it on my server, with the api keys they gave me 3 post the route of the file in the user's device to the server 4 upload the file to storage 5 whenever i want to, send request to backend and download images i dont know, is this everything i have to do? do i have to do something with the database? anyways thanks btw im using react native(expo) and node js
Olyno
Olyno3y ago
Yeah it sounds good to me
LeBruno James
LeBruno JamesOP3y ago
aight aight cool hey, im getting this error using supabase and expo:
ERROR Error: URL.hostname is not implemented
ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
ERROR Error: URL.hostname is not implemented
ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
This is my code, also i dont know if im uploading the image the right way: client.js:
import { createClient } from "@supabase/supabase-js";

const supabaseUrl = <My supabase url>;
const supabaseAnonKey = <My supabase anon key>;

const supabase = createClient(supabaseUrl, supabaseAnonKey);

export default supabase;
import { createClient } from "@supabase/supabase-js";

const supabaseUrl = <My supabase url>;
const supabaseAnonKey = <My supabase anon key>;

const supabase = createClient(supabaseUrl, supabaseAnonKey);

export default supabase;
upload image:
import supabase from "../supabase/client";

const handleSubmit = () => {

const path =
Math.random() + "." + images[0].uri.substring(lastIndexOf("/") + 1);

supabase.storage.from("images").upload(path, images[0].file);
};
import supabase from "../supabase/client";

const handleSubmit = () => {

const path =
Math.random() + "." + images[0].uri.substring(lastIndexOf("/") + 1);

supabase.storage.from("images").upload(path, images[0].file);
};
pick image:
function ImageInput({ onSelectImage, active }) {

const handlePress = async () => {
const result = await ImagePicker.launchImageLibraryAsync({
skipBackup: true,
path: "images",
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0.5,
aspect: [4, 3],
});

if (result.canceled) {
return;
}

const res = await fetch(result.assets[0].uri);
const blob = res.blob();
var file = new File([blob], "test.png", {
type: "image/png",
});
onSelectImage({ uri: result.assets[0].uri, file: file });
};
function ImageInput({ onSelectImage, active }) {

const handlePress = async () => {
const result = await ImagePicker.launchImageLibraryAsync({
skipBackup: true,
path: "images",
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0.5,
aspect: [4, 3],
});

if (result.canceled) {
return;
}

const res = await fetch(result.assets[0].uri);
const blob = res.blob();
var file = new File([blob], "test.png", {
type: "image/png",
});
onSelectImage({ uri: result.assets[0].uri, file: file });
};
Olyno
Olyno3y ago
Are you getting this error when you start your react native app? @LeBruno James I think there is all that stuff missing, creating this issue: To install
@react-native-async-storage/async-storage react-native-url-polyfill
@react-native-async-storage/async-storage react-native-url-polyfill
To change
// client.js

import AsyncStorage from '@react-native-async-storage/async-storage';

export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: AsyncStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
// client.js

import AsyncStorage from '@react-native-async-storage/async-storage';

export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: AsyncStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
// App.jsx
import 'react-native-url-polyfill/auto';

// ...
// App.jsx
import 'react-native-url-polyfill/auto';

// ...
LeBruno James
LeBruno JamesOP3y ago
oh, okay I'll do that, i though that was for authentication, that's why I didn't write it thanks i love you man it worked i mean it isnt uploading but it stopped showing me that error
Olyno
Olyno3y ago
Check if the path variable is right, and you're uploading the right file
LeBruno James
LeBruno JamesOP3y ago
its giving me this warn:
WARN Possible Unhandled Promise Rejection (id: 3):
TypeError: Network request failed
WARN Possible Unhandled Promise Rejection (id: 3):
TypeError: Network request failed
but the path and file are right this is my code:
const handleSubmit = async () => {
for (const image of images) {
const formData = new FormData();

console.log("this is the image: ", image);

const path = image.uri.substring(image.uri.lastIndexOf("/") + 1);

console.log("this is the path: ", path);

formData.append("image", image);

console.log("this is the form data: ", formData);

const { error, data } = await supabase.storage
.from("images")
.upload(path, formData);

if (error) {
console.log(error);
}
console.log(data);
}
};
const handleSubmit = async () => {
for (const image of images) {
const formData = new FormData();

console.log("this is the image: ", image);

const path = image.uri.substring(image.uri.lastIndexOf("/") + 1);

console.log("this is the path: ", path);

formData.append("image", image);

console.log("this is the form data: ", formData);

const { error, data } = await supabase.storage
.from("images")
.upload(path, formData);

if (error) {
console.log(error);
}
console.log(data);
}
};
this is the code for picking images
const result = await ImagePicker.launchImageLibraryAsync({
skipBackup: true,
path: "images",
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0.5,
aspect: [4, 3],
});

if (result.canceled) {
return;
}

onSelectImage({
uri: result.assets[0].uri,
type: result.assets[0].type,
name: result.assets[0].fileName,
});
const result = await ImagePicker.launchImageLibraryAsync({
skipBackup: true,
path: "images",
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0.5,
aspect: [4, 3],
});

if (result.canceled) {
return;
}

onSelectImage({
uri: result.assets[0].uri,
type: result.assets[0].type,
name: result.assets[0].fileName,
});
Olyno
Olyno3y ago
You can't upload a formData, it's not supported I think. You only can upload File So basically you should upload result.assets[0]
LeBruno James
LeBruno JamesOP3y ago
async function uploadAvatar() {
try {
setUploading(true)

const file = await DocumentPicker.pickSingle({
presentationStyle: 'fullScreen',
copyTo: 'cachesDirectory',
type: types.images,
mode: 'open',
})

const photo = {
uri: file.fileCopyUri,
type: file.type,
name: file.name,
}

const formData = new FormData()
formData.append('file', photo)

const fileExt = file.name.split('.').pop()
const filePath = `${Math.random()}.${fileExt}`

let { error } = await supabase.storage.from('avatars').upload(filePath, formData)

if (error) {
throw error
}

onUpload(filePath)
} catch (error) {
if (isCancel(error)) {
console.warn('cancelled')
// User cancelled the picker, exit any dialogs or menus and move on
} else if (isInProgress(error)) {
console.warn('multiple pickers were opened, only the last will be considered')
} else if (error instanceof Error) {
Alert.alert(error.message)
} else {
throw error
}
} finally {
setUploading(false)
}
}
async function uploadAvatar() {
try {
setUploading(true)

const file = await DocumentPicker.pickSingle({
presentationStyle: 'fullScreen',
copyTo: 'cachesDirectory',
type: types.images,
mode: 'open',
})

const photo = {
uri: file.fileCopyUri,
type: file.type,
name: file.name,
}

const formData = new FormData()
formData.append('file', photo)

const fileExt = file.name.split('.').pop()
const filePath = `${Math.random()}.${fileExt}`

let { error } = await supabase.storage.from('avatars').upload(filePath, formData)

if (error) {
throw error
}

onUpload(filePath)
} catch (error) {
if (isCancel(error)) {
console.warn('cancelled')
// User cancelled the picker, exit any dialogs or menus and move on
} else if (isInProgress(error)) {
console.warn('multiple pickers were opened, only the last will be considered')
} else if (error instanceof Error) {
Alert.alert(error.message)
} else {
throw error
}
} finally {
setUploading(false)
}
}
` its uploading the form data in the supabase website but im gonna try with that thanks
Olyno
Olyno3y ago
Nevermind, i was reading the Svelte guide 😂 Do you have any error message?
LeBruno James
LeBruno JamesOP3y ago
no, just that oh lol its not working either with result.assets[0]
Olyno
Olyno3y ago
hmmm Can you have a look in your Supabase dashboard? There is a log tab where you can inspect what is happening. It could help on the issue By the way, do we know if it's the supabase.storage.from('avatars').upload method which throws the error, or is it the DocumentPicker.pickSingle method?
LeBruno James
LeBruno JamesOP3y ago
its the upload, but im using expo imagePicker is that a problem? that im using expo image picker
Olyno
Olyno3y ago
OOOH Wait I maybe found the issue Just here: formData.append("image", image); if you take a look in the expo example, it's formData.append("file", image);
LeBruno James
LeBruno JamesOP3y ago
oh oh oh, im gonna try that still not working 😓
Olyno
Olyno3y ago
:/ I think it's the best shot we have
LeBruno James
LeBruno JamesOP3y ago
how do i that
LeBruno James
LeBruno JamesOP3y ago
No description
LeBruno James
LeBruno JamesOP3y ago
this? oh wait i have some logs cool
Olyno
Olyno3y ago
You should have some logs in the "Storage" tab on the left
LeBruno James
LeBruno JamesOP3y ago
Metadata
[
{
"context": [
{
"pid": 29
}
],
"err": [],
"error": [
{
"expiredAt": null,
"httpStatusCode": null,
"message": null,
"metadata": [
{
"bucketId": "images",
"name": "0.05167870549681086.968c9719-8c7a-4873-89f0-fd2e88e754b3.jpeg"
}
],
"name": null,
"originalError": [],
"postgresError": [
{
"code": "42501",
"details": null,
"message": "new row violates row-level security policy for table \"objects\""
}
],
"status": 401,
"statusCode": null,
"validation": [],
"validationContext": null
}
],
"level": "info",
"req": [
{
"headers": [
{
"accept": null,
"content_length": "162",
"content_type": "multipart/form-data; boundary=6f72e77e-7656-4726-8ec9-fe55ad99d695",
"referer": null,
"user_agent": "okhttp/4.9.2",
"x_client_info": "supabase-js/2.1.1",
"x_forwarded_proto": "https"
}
],
"method": "POST",
"url": "/object/images/0.05167870549681086.968c9719-8c7a-4873-89f0-fd2e88e754b3.jpeg"
}
],
"res": [
{
"statusCode": 400
}
],
"responseTime": 398.54179800022393,
"results": [],
}
]
[
{
"context": [
{
"pid": 29
}
],
"err": [],
"error": [
{
"expiredAt": null,
"httpStatusCode": null,
"message": null,
"metadata": [
{
"bucketId": "images",
"name": "0.05167870549681086.968c9719-8c7a-4873-89f0-fd2e88e754b3.jpeg"
}
],
"name": null,
"originalError": [],
"postgresError": [
{
"code": "42501",
"details": null,
"message": "new row violates row-level security policy for table \"objects\""
}
],
"status": 401,
"statusCode": null,
"validation": [],
"validationContext": null
}
],
"level": "info",
"req": [
{
"headers": [
{
"accept": null,
"content_length": "162",
"content_type": "multipart/form-data; boundary=6f72e77e-7656-4726-8ec9-fe55ad99d695",
"referer": null,
"user_agent": "okhttp/4.9.2",
"x_client_info": "supabase-js/2.1.1",
"x_forwarded_proto": "https"
}
],
"method": "POST",
"url": "/object/images/0.05167870549681086.968c9719-8c7a-4873-89f0-fd2e88e754b3.jpeg"
}
],
"res": [
{
"statusCode": 400
}
],
"responseTime": 398.54179800022393,
"results": [],
}
]
here content-type is multipart/form-data;
Olyno
Olyno3y ago
new row violates row-level security policy for table \"objects\" looks like we got the error
LeBruno James
LeBruno JamesOP3y ago
yeah
Olyno
Olyno3y ago
Supabase Documentation
Storage
Use Supabase to store and serve files.
LeBruno James
LeBruno JamesOP3y ago
i dont have anything set up in the database do i have to do somethin with the database? like the schema ?
Olyno
Olyno3y ago
By default, a lot of things are public with Supabase (your tables). To restrict the access, there is a RLS system. Looks like the storage system is restricted by default, meaning you can't have access directly. You can either setup your own rule, or make it public access
LeBruno James
LeBruno JamesOP3y ago
oh okay, so how do i make it publlic
Olyno
Olyno3y ago
It's not really complicated. I dropped you the link above, there is some examples. You simply execute the code in the SQL editor of the Supabase dashboard A total access would be:
-- 1. Allow public access to any files in the "public" bucket
create policy "Public Access"
on storage.objects for select
using ( bucket_id = 'public' );
-- 1. Allow public access to any files in the "public" bucket
create policy "Public Access"
on storage.objects for select
using ( bucket_id = 'public' );
LeBruno James
LeBruno JamesOP3y ago
oh ok thanks a lot, lets see if it works
Olyno
Olyno3y ago
Of course, your bucket name is not "public", so you will have to change the name to your bucket name
LeBruno James
LeBruno JamesOP3y ago
No description
LeBruno James
LeBruno JamesOP3y ago
i need to run it here?
Olyno
Olyno3y ago
Yep
LeBruno James
LeBruno JamesOP3y ago
ok i executed it lets see awww cmon man
Olyno
Olyno3y ago
Not working? :/
LeBruno James
LeBruno JamesOP3y ago
no 😦
Olyno
Olyno3y ago
Did you change the name of the bucket? 🤔
LeBruno James
LeBruno JamesOP3y ago
yeah create policy "Public Access" on storage.objects for select using ( bucket_id = 'images' ); like this right?
Olyno
Olyno3y ago
Yep Do we have anything in logs?
LeBruno James
LeBruno JamesOP3y ago
nothing new im gonna go and come back tomorrow with a clear mind thanks bye
Olyno
Olyno3y ago
If you want, we could go in voice chat tomorrow and try to solve that?
LeBruno James
LeBruno JamesOP3y ago
umm id rather talk here, cause my english isnt too good, im spanish, and im 14 so my parents are home
and I'm embarrassed to speak in front of them lol sorry
Olyno
Olyno3y ago
No problem ahah, i was thinking about a screen sharing, but that's okay!
LeBruno James
LeBruno JamesOP3y ago
oh i could share screen
Olyno
Olyno3y ago
We can try that tomorrow :p
LeBruno James
LeBruno JamesOP3y ago
bro i stopped getting the warn but got a new error in the console
LOG {"error": "Invalid JWT", "message": "new row violates row-level security policy for table \"objects\"", "statusCode": "401"}
LOG null
LOG {"error": "Invalid JWT", "message": "new row violates row-level security policy for table \"objects\"", "statusCode": "401"}
LOG null
for (const image of images) {
// const formData = new FormData();
console.log("this is the image: ", image);
const path = image.uri.substring(image.uri.lastIndexOf("/") + 1);

console.log("this is the path: ", path);

await fetch(image.uri).then(async (response) => {
const { error, data } = await supabase.storage
.from("images")
.upload(path, response.blob());

if (error) {
console.log(error);
}
console.log(data);
});
// formData.append("file", image);
// console.log("this is the form data: ", formData._parts);
}
for (const image of images) {
// const formData = new FormData();
console.log("this is the image: ", image);
const path = image.uri.substring(image.uri.lastIndexOf("/") + 1);

console.log("this is the path: ", path);

await fetch(image.uri).then(async (response) => {
const { error, data } = await supabase.storage
.from("images")
.upload(path, response.blob());

if (error) {
console.log(error);
}
console.log(data);
});
// formData.append("file", image);
// console.log("this is the form data: ", formData._parts);
}
Olyno
Olyno3y ago
It still says there is an issue with RLS, no idea why
LeBruno James
LeBruno JamesOP3y ago
yeah, thats what i found too but idk what to do
LeBruno James
LeBruno JamesOP3y ago
No description
LeBruno James
LeBruno JamesOP3y ago
should i do this? i did it its still not working its the rls but idk whaaaaatttt 😩
Olyno
Olyno3y ago
Try to login to your database using pg_dump and the connection string of your instance, and do \d pg_policy to list all existing policies for your database It could be an issue from another policy
LeBruno James
LeBruno JamesOP3y ago
im going to sleep ill try that tmr its 00:50
Olyno
Olyno3y ago
Ahah same here :p
LeBruno James
LeBruno JamesOP3y ago
where do i do this?
Olyno
Olyno3y ago
In the console directly. When you're connected to your database using pg_dump, you can simply paste this special command inside
LeBruno James
LeBruno JamesOP3y ago
i think i found out whats wrong
LeBruno James
LeBruno JamesOP3y ago
GitHub
Can I use only Supabase's storage solution? · Discussion #6097 · su...
I assume this is the case, but I have to make sure (completely new to supabase/PostgreSQL). Am I able to use Supabase&#39;s storage solution and utilize all its security features without using ...
LeBruno James
LeBruno JamesOP3y ago
i already have authentication, i coded it myself, so idk if i should use supabase auth holy sh*t bro @Olyno i fixed it it uploaded im so happy
LeBruno James
LeBruno JamesOP3y ago
No description
LeBruno James
LeBruno JamesOP3y ago
i think the image is wrong format but it worked
Olyno
Olyno3y ago
Wait, how? How did you manage to fix that?!
LeBruno James
LeBruno JamesOP3y ago
i did it its working all of it so what i did is run this
create policy "Anyone can upload an image."
on storage.objects for insert
with check ( bucket_id = 'images' );
create policy "Anyone can upload an image."
on storage.objects for insert
with check ( bucket_id = 'images' );
` in the sql editor and it wasnnt posting as images then, but i managed to solve it by getting the base 64 of the image and decoding it to an array buffer
import { decode } from "base64-arraybuffer";

for (const image of images) {
// const formData = new FormData();
console.log("this is the image: ", image);
const path = image.uri.substring(image.uri.lastIndexOf("/") + 1);

console.log("this is the path: ", path);

// formData.append("file", image);

// await fetch(image.uri).then(async (response) => {
const { error, data } = await supabase.storage
.from("post-images")
.upload(path, decode(image.base64), {
contentType: "image/png",
});

if (error) {
console.log(error);
}
console.log(data);
// });

// console.log("this is the form data: ", formData._parts);
}
import { decode } from "base64-arraybuffer";

for (const image of images) {
// const formData = new FormData();
console.log("this is the image: ", image);
const path = image.uri.substring(image.uri.lastIndexOf("/") + 1);

console.log("this is the path: ", path);

// formData.append("file", image);

// await fetch(image.uri).then(async (response) => {
const { error, data } = await supabase.storage
.from("post-images")
.upload(path, decode(image.base64), {
contentType: "image/png",
});

if (error) {
console.log(error);
}
console.log(data);
// });

// console.log("this is the form data: ", formData._parts);
}
thanks a lot man you were very helpful 🤝 so i have a question, when i want to display the image, should i just display it with the link, or download the image or something?
Olyno
Olyno3y ago
Oooooh wait, i'm just dumb. The RLS i sent you before was for select, not insert 😂 It should be as link for sure :p
LeBruno James
LeBruno JamesOP3y ago
lmaoo oh okay, so download is just if you want the image in your device?
Olyno
Olyno3y ago
The download method is to get the file. It's like downloading the file in cache. From this file, you need a link to display it :p
LeBruno James
LeBruno JamesOP3y ago
ohh okay thanks man
Olyno
Olyno3y ago
You did all the thing 😅 Thanks to you to show me my mistake 😄
LeBruno James
LeBruno JamesOP3y ago
lol well it was very nice talking to you, cya btw is the supabase website working for you?
LeBruno James
LeBruno JamesOP3y ago
No description
Olyno
Olyno3y ago
Yep, working on my side
LeBruno James
LeBruno JamesOP3y ago
idk why do you use node js? whats your tech stack
Olyno
Olyno3y ago
Yeah, Node mainly
LeBruno James
LeBruno JamesOP3y ago
im getting this error all the time and it sometimes stop oh cool look
Olyno
Olyno3y ago
No idea xD
LeBruno James
LeBruno JamesOP3y ago
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
at NativeConnection.Connection.openUri (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\connection.js:824:32)
at E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\index.js:413:10
at E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
at new Promise (<anonymous>)
at promiseOrCallback (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
at Mongoose._promiseOrCallback (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\index.js:1266:10)
at Mongoose.connect (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\index.js:412:20)
at file:///E:/9.%20Scripts/Javascript/homework-app/server/index.js:27:4
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'ac-78j425j-shard-00-00.6p6njei.mongodb.net:27017' => [ServerDescription],
'ac-78j425j-shard-00-01.6p6njei.mongodb.net:27017' => [ServerDescription],
'ac-78j425j-shard-00-02.6p6njei.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
at NativeConnection.Connection.openUri (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\connection.js:824:32)
at E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\index.js:413:10
at E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
at new Promise (<anonymous>)
at promiseOrCallback (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
at Mongoose._promiseOrCallback (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\index.js:1266:10)
at Mongoose.connect (E:\9. Scripts\Javascript\homework-app\server\node_modules\mongoose\lib\index.js:412:20)
at file:///E:/9.%20Scripts/Javascript/homework-app/server/index.js:27:4
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'ac-78j425j-shard-00-00.6p6njei.mongodb.net:27017' => [ServerDescription],
'ac-78j425j-shard-00-01.6p6njei.mongodb.net:27017' => [ServerDescription],
'ac-78j425j-shard-00-02.6p6njei.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}
its so annoying

Did you find this page helpful?