> ## Documentation Index
> Fetch the complete documentation index at: https://docs.browserbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Build an AI-powered data extraction agent that pulls product data from e-commerce sites and stores it in MongoDB with automatic schema validation and data analysis capabilities.

<Card title="What You'll Build" icon="rocket" horizontal>
  An AI-powered data extraction agent that pulls product data from e-commerce sites and stores it in MongoDB with automatic schema validation and data analysis.
</Card>

## Before you start

Ensure you have these requirements ready:

<CardGroup cols={3}>
  <Card title="Node.js 16+" icon="node-js" href="https://nodejs.org/">
    Required runtime environment
  </Card>

  <Card title="MongoDB" icon="database" href="https://www.mongodb.com/atlas">
    Local install or MongoDB Atlas
  </Card>

  <Card title="API Access" icon="key" href="https://www.browserbase.com/overview">
    Browserbase API key
  </Card>
</CardGroup>

## Step 1: Project setup

### Clone and install

```bash theme={null}
# Clone the integration template
npx degit browserbase/integrations/examples/integrations/mongodb/typescript browserbase-mongodb
cd browserbase-mongodb

# Install all dependencies
npm install

# Install browser binaries
npx playwright install
```

<Accordion title="What gets installed?">
  **Core packages:**

  * `@browserbasehq/stagehand` - AI-powered data extraction
  * `mongodb` - MongoDB driver for data storage
  * `zod` - Schema validation for type safety

  **Utilities:**

  * `chalk` & `boxen` - Terminal styling and output formatting
  * `playwright` - Browser automation engine
</Accordion>

## Step 2: Start MongoDB

<Warning>
  **Required**: MongoDB must be running on your system before proceeding. Start it with `mongod` if installed locally, or ensure your MongoDB Atlas connection is ready.
</Warning>

If using local MongoDB, ensure it's running:

```bash theme={null}
# Start MongoDB (if installed locally)
mongod
```

<Info>
  **MongoDB Atlas users** can skip this step as the database is already hosted in the cloud.
</Info>

## Step 3: Configuration

### Environment variables

Create your `.env` file with the required configuration:

<CodeGroup>
  ```bash Local MongoDB theme={null}
  # Browserbase Configuration (Recommended)
  BROWSERBASE_API_KEY=your_browserbase_api_key

  # MongoDB Configuration
  MONGO_URI=mongodb://localhost:27017
  DB_NAME=scraper_db

  # Stagehand Configuration
  ANTHROPIC_API_KEY=your_anthropic_api_key_here
  ```

  ```bash MongoDB Atlas theme={null}
  # Browserbase Configuration (Recommended)
  BROWSERBASE_API_KEY=your_browserbase_api_key

  # MongoDB Atlas Configuration
  MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/
  DB_NAME=scraper_db

  # Stagehand Configuration  
  ANTHROPIC_API_KEY=your_anthropic_api_key_here
  ```
</CodeGroup>

## Step 4: Configure Stagehand

The integration uses Browserbase cloud browsers:

```typescript stagehand.config.ts theme={null}
const StagehandConfig: V3Options = {
  verbose: 1,
  domSettleTimeout: 30_000,
  
  // LLM Configuration  
  model: "anthropic/claude-sonnet-4-6",
  
  // Run in Browserbase cloud (Recommended)
  env: "BROWSERBASE",
  apiKey: process.env.BROWSERBASE_API_KEY,
  browserbaseSessionCreateParams: {
    browserSettings: {
      blockAds: true,
      viewport: { width: 1024, height: 768 },
    },
  },
};
```

## Step 5: Run your first extraction

**What happens when you run the agent:**

1. Connects to MongoDB and creates necessary collections
2. Navigates to Amazon laptop category
3. Extracts product listings with AI-powered data extraction
4. Extracts detailed information for the first 3 products
5. Stores all data in MongoDB with schema validation
6. Runs analysis queries and displays results

### Execute the extraction

```bash theme={null}
npm start
```

## Customization options

### Extend data schema

Add custom fields to capture more product information:

```typescript theme={null}
const ProductSchema = z.object({
  // Existing fields...
  title: z.string(),
  price: z.string().optional(),
  rating: z.string().optional(),
  
  // Add your custom fields
  brand: z.string().optional(),
  availability: z.string().optional(),
  shippingInfo: z.string().optional(),
  specifications: z.array(z.string()).optional(),
  customerReviews: z.number().optional(),
});
```

### Custom extraction instructions

Modify the AI extraction to capture specific data:

```typescript theme={null}
const data = await stagehand.extract(
  `Extract comprehensive product information including:
    - Brand and model details
    - Detailed specifications
    - Availability and shipping information
    - Customer ratings and review counts`,
  ProductSchema,
);
```

## What's next?

Now that you have a working MongoDB + Stagehand integration:

<CardGroup cols={2}>
  <Card title="Scale your extraction" icon="globe" href="https://www.mongodb.com/docs/atlas/getting-started/">
    Learn how to scale your data extraction across multiple sites and handle larger datasets.
  </Card>

  <Card title="Deploy to production" icon="server" href="https://www.browserbase.com/overview">
    Deploy your extraction pipeline to production with Browserbase.
  </Card>
</CardGroup>

***

<Info>
  **Need help?** Join the [Stagehand Slack community](https://stagehand.dev/slack) for support and to share your projects!
</Info>
