Integrate Mongoose Studio as middleware in your Express app. The following will mount Mongoose Studio at /studio. Remember to use await!
const mongoose = require('mongoose');
const studio = require('@mongoosejs/studio/express');
// other code...
// Mount Mongoose Studio on '/studio'.
// If you want a different path, change '/studio' to your desired path.
// Make sure to use await!
app.use('/studio', await studio('/studio/api', mongoose));
Mongoose Connections
If you create a new Mongoose connection using mongoose.createConnection(), you can pass it to Mongoose Studio as follows:
const mongoose = require('mongoose');
const studio = require('@mongoosejs/studio/express');
// other code...
// Create a new Mongoose connection
const connection = mongoose.createConnection('mongodb://localhost:27017/mydb');
// Mount Mongoose Studio on '/studio'.
app.use('/studio', await studio('/studio/api', connection));
Mongoose Studio currently only supports a single Mongoose connection.
Configuration
If you have a Mongoose Studio Pro API key or wish to use advanced features, like providing your own OpenAI key, pass options as follows:
const opts = {
apiKey: process.env.MONGOOSE_STUDIO_API_KEY, // optional for Pro
model: 'gpt-4o-mini', // optional ChatGPT model
openAIAPIKey: process.env.OPENAI_API_KEY, // optional for chat
anthropicAPIKey: process.env.ANTHROPIC_API_KEY, // optional for chat
googleGeminiAPIKey: process.env.GOOGLE_GEMINI_API_KEY // optional for chat
};
app.use('/studio', await studio('/studio/api', mongoose, opts));
Accessing Mongoose Studio
- In local development, visit
http://localhost:3000/studio(or the path you choose). - In production, Studio will be at
your-app.com/studio.