
I am trying to connect my mongodb to flutter and this is how my database.dart
file looks
import 'package:mongo_dart/mongo_dart.dart';
import 'package:restro_app/database/constant.dart';
import 'package:restro_app/models/menu_model.dart';
class MongoDatabase {
static var db, userCollection;
//Connection to the database
static connect() async {
db = await Db.create(MONGO_CONN_URL);
await db.open();
userCollection = db.collection(DATA_COLLECTION);
}
// More code..

But when I started to debug I realised that the variable db isn't getting any values

it returns Db(null, null)

const MONGO_CONN_URL = "mongodb+srv://127.0.0.1:27017/Restaurant";

This is how my connection string looks

Not sure what is going wrong

Hi 👋

127.0.0.1 - is localhost?

You need to use public IP or a domain to connect to their MongoDB server.

FYI, since this is an Appwrite (https://appwrite.io/) discord server, for general flutter questions, you might find more help in a Flutter discord server (https://flutter.dev/community#community-grid).

[SOLVED] How to connect MongoDB with flutter

Closing this thread for now, if you have appwrite specific questions, please open a new thread 🙂
Recommended threads
- Document Data is null.
I'm using flutter and I've just got everything set up, the document meta data is null but the actual query is fine. (see screenshot) The permission I have ar...
- Flutter native Google Sign Up with googl...
Hey I want to use the native login instead of the WebView. Do you have any experience on that and has Appwrite to plan this support?
- cli 5.0.5 command for pull and push of d...
Hi i am using selfhosted appwrite 1.5.10, for migration (duplicate project) purpose i am using cli 5.0.5, but i am unable to find commands for pull and push, wh...
