Skip to content

Commit 1260a79

Browse files
cleanup and READMEs
1 parent 276bae3 commit 1260a79

17 files changed

Lines changed: 257 additions & 61 deletions

File tree

mflix/README-JAVA-SPRING.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ Open your browser and navigate to:
100100

101101
## Features
102102

103-
- **Browse Movies:** View a paginated list of movies from the sample_mflix dataset
104-
- **Search:** Full-text search using MongoDB Search
105-
- **Filter:** Filter movies by genre, year, rating, and more
106-
- **Movie Details:** View detailed information about each movie
107-
- **Aggregations:** Complex data aggregations and analytics
103+
- **Browse Movies:** View a paginated list of movies from the
104+
sample_mflix dataset
105+
- **CRUD Operations:** Create, read, update and delete movies by using
106+
the MongoDB Java driver
107+
- **Search:** Search movies with filters by using MongoDB Search
108+
- **Vector Search:** Search movie plots with similar search terms by
109+
using MongoDB Vector Search
110+
- **Aggregations:** View data aggregations and analytics built with
111+
aggregation pipelines
108112

109113
## Development
110114

@@ -176,5 +180,5 @@ If you have problems running the sample app, please check the following:
176180
- [ ] Verify that you have no firewalls blocking access to the server or client ports.
177181

178182
If you have verified the above and still have issues, please
179-
[open an issue](https://github.com/mongodb/docs-sample-apps/issues/new/choose)
180-
on the source repository `mongodb/docs-sample-apps`.
183+
[open an issue](https://github.com/mongodb/sample-app-java-mflix/issues/new/choose)
184+
on the source repository `mongodb/sample-app-java-mflix`.

mflix/README-JAVASCRIPT-EXPRESS.md

Lines changed: 187 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,196 @@
11
# JavaScript Express.js MongoDB Sample MFlix Application
22

3-
[TODO: Add intro]
3+
This is a full-stack movie browsing application built with Express.js and Next.js, demonstrating MongoDB operations using the `sample_mflix` dataset. The application showcases CRUD operations, aggregations, and MongoDB Search using the native MongoDB Node.js driver.
4+
5+
## Project Structure
46

57
```
6-
├── README.md
7-
├── client/ # Next.js frontend
8-
└── server/ # Express.js backend
8+
├── README-JAVASCRIPT-EXPRESS.md
9+
├── client/ # Next.js frontend (TypeScript)
10+
└── server/js-express/ # Express.js backend
11+
├── src/
12+
├── package.json
13+
├── .env.example
14+
└── tsconfig.json
915
```
1016

17+
## Prerequisites
18+
19+
- **Node.js 22** or higher
20+
- **MongoDB Atlas cluster or local deployment** with the `sample_mflix` dataset loaded
21+
- [Load sample data](https://www.mongodb.com/docs/atlas/sample-data/)
22+
- **npm** (included with Node.js)
23+
1124
## Getting Started
1225

13-
[TODO: Add getting started instructions explaining how to set connection string, start server, start client, etc.]
26+
### 1. Configure the Backend
27+
28+
Navigate to the Express server directory:
29+
30+
```bash
31+
cd server/js-express
32+
```
33+
34+
Create a `.env` file from the example:
35+
36+
```bash
37+
cp .env.example .env
38+
```
39+
40+
Edit the `.env` file and set your MongoDB connection string:
41+
42+
```env
43+
# MongoDB Configuration
44+
# Replace with your MongoDB Atlas connection string
45+
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/sample_mflix?retryWrites=true&w=majority
46+
47+
# Server Configuration
48+
PORT=3001
49+
NODE_ENV=development
50+
51+
# CORS Configuration (frontend URL)
52+
CORS_ORIGIN=http://localhost:3000
53+
54+
# Optional: Enable MongoDB Search tests
55+
# Uncomment the following line to enable Search tests
56+
# ENABLE_SEARCH_TESTS=true
57+
```
58+
59+
**Note:** Replace `<username>`, `<password>`, and `<cluster>` with your actual MongoDB Atlas credentials.
60+
61+
### 2. Install Backend Dependencies
62+
63+
From the `server/js-express` directory, run:
64+
65+
```bash
66+
npm install
67+
```
68+
69+
### 3. Start the Backend Server
70+
71+
From the `server/js-express` directory, run:
72+
73+
```bash
74+
# Development mode with hot reloading
75+
npm run dev
76+
77+
# Or production mode
78+
npm run build
79+
npm start
80+
```
81+
82+
The server will start on `http://localhost:3001`. You can verify it's running by visiting:
83+
- API root: http://localhost:3001/
84+
- API documentation (Swagger UI): http://localhost:3001/api-docs
85+
86+
### 4. Configure and Start the Frontend
87+
88+
Open a new terminal and navigate to the client directory:
89+
90+
```bash
91+
cd client
92+
```
93+
94+
Install dependencies:
95+
96+
```bash
97+
npm install
98+
```
99+
100+
Start the development server:
101+
102+
```bash
103+
npm run dev
104+
```
105+
106+
The Next.js application will start on `http://localhost:3000`.
107+
108+
### 5. Access the Application
109+
110+
Open your browser and navigate to:
111+
- **Frontend:** http://localhost:3000
112+
- **Backend API:** http://localhost:3001
113+
- **API Documentation:** http://localhost:3001/api-docs
114+
115+
## Features
116+
117+
- **Browse Movies:** View a paginated list of movies from the
118+
sample_mflix dataset
119+
- **CRUD Operations:** Create, read, update and delete movies by using
120+
the MongoDB Node.js driver
121+
- **Search:** Search movies with filters by using MongoDB Search
122+
- **Vector Search:** Search movie plots with similar search terms by
123+
using MongoDB Vector Search
124+
- **Aggregations:** View data aggregations and analytics built with
125+
aggregation pipelines
126+
127+
## Development
128+
129+
### Backend Development
130+
131+
The Express.js backend uses:
132+
- **Express.js 5** for REST API
133+
- **MongoDB Node.js Driver** for database operations
134+
- **TypeScript** for type safety
135+
- **Swagger** for API documentation
136+
- **Jest** for testing
137+
138+
To run tests:
139+
140+
```bash
141+
cd server/js-express
142+
npm test
143+
```
144+
145+
To run tests with coverage:
146+
147+
```bash
148+
cd server/js-express
149+
npm run test:coverage
150+
```
151+
152+
### Frontend Development
153+
154+
The Next.js frontend uses:
155+
- **React 19** with TypeScript
156+
- **Next.js 16** with App Router
157+
- **Turbopack** for fast development builds
158+
159+
#### Development Mode
160+
161+
For active development with hot reloading and fast refresh:
162+
163+
```bash
164+
cd client
165+
npm run dev
166+
```
167+
168+
This starts the development server on `http://localhost:3000` with Turbopack for fast rebuilds.
169+
170+
#### Production Build
171+
172+
To create an optimized production build and run it:
173+
174+
```bash
175+
cd client
176+
npm run build # Creates optimized production build
177+
npm start # Starts production server
178+
```
179+
180+
The production build:
181+
- Minifies and optimizes JavaScript and CSS
182+
- Optimizes images and assets
183+
- Generates static pages where possible
184+
- Provides better performance for end users
185+
186+
#### Linting
187+
188+
To check code quality:
189+
190+
```bash
191+
cd client
192+
npm run lint
193+
```
14194

15195
## Issues
16196

@@ -22,5 +202,5 @@ If you have problems running the sample app, please check the following:
22202
- [ ] Verify that you have no firewalls blocking access to the server or client ports.
23203

24204
If you have verified the above and still have issues, please
25-
[open an issue](https://github.com/mongodb/docs-sample-apps/issues/new/choose)
26-
on the source repository `mongodb/docs-sample-apps`.
205+
[open an issue](https://github.com/mongodb/sample-app-nodejs-mflix/issues/new/choose)
206+
on the source repository `mongodb/sample-app-nodejs-mflix`.

mflix/client/app/components/SearchMovieModal/SearchMovieModal.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface SearchParams {
2828
cast?: string;
2929
limit?: number;
3030
skip?: number;
31-
search_operator?: 'must' | 'should' | 'mustNot' | 'filter';
31+
searchOperator?: 'must' | 'should' | 'mustNot' | 'filter';
3232
// Vector Search fields
3333
q?: string;
3434
}
@@ -42,7 +42,7 @@ interface SearchFormData {
4242
writers: string;
4343
cast: string;
4444
limit: string;
45-
search_operator: 'must' | 'should' | 'mustNot' | 'filter';
45+
searchOperator: 'must' | 'should' | 'mustNot' | 'filter';
4646
// Vector Search fields
4747
q: string;
4848
}
@@ -56,7 +56,7 @@ const getInitialFormData = (): SearchFormData => ({
5656
writers: '',
5757
cast: '',
5858
limit: '20',
59-
search_operator: 'must',
59+
searchOperator: 'must',
6060
// Vector Search fields
6161
q: '',
6262
});
@@ -115,7 +115,7 @@ export default function SearchMovieModal({
115115

116116
if (formData.searchType === 'mongodb-search') {
117117
// Add MongoDB Search specific parameters
118-
searchParams.search_operator = formData.search_operator;
118+
searchParams.searchOperator = formData.searchOperator;
119119
searchParams.skip = 0; // Always start from beginning for new search
120120

121121
if (formData.plot.trim()) {
@@ -316,13 +316,13 @@ export default function SearchMovieModal({
316316

317317
{/* Search Operator */}
318318
<div className={styles.formGroup}>
319-
<label htmlFor="search_operator" className={styles.label}>
319+
<label htmlFor="searchOperator" className={styles.label}>
320320
Search Logic
321321
</label>
322322
<select
323-
id="search_operator"
324-
value={formData.search_operator}
325-
onChange={(e) => handleInputChange('search_operator', e.target.value)}
323+
id="searchOperator"
324+
value={formData.searchOperator}
325+
onChange={(e) => handleInputChange('searchOperator', e.target.value)}
326326
className={styles.input}
327327
disabled={isLoading}
328328
>
@@ -333,7 +333,7 @@ export default function SearchMovieModal({
333333
))}
334334
</select>
335335
<small className={styles.searchOperatorDescription}>
336-
{searchOperatorOptions.find(opt => opt.value === formData.search_operator)?.description}
336+
{searchOperatorOptions.find(opt => opt.value === formData.searchOperator)?.description}
337337
</small>
338338
</div>
339339
</>

mflix/client/app/lib/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ export async function searchMovies(searchParams: {
593593
cast?: string;
594594
limit?: number;
595595
skip?: number;
596-
search_operator?: 'must' | 'should' | 'mustNot' | 'filter';
596+
searchOperator?: 'must' | 'should' | 'mustNot' | 'filter';
597597
}): Promise<{ success: boolean; error?: string; movies?: Movie[]; hasNextPage?: boolean; hasPrevPage?: boolean; totalCount?: number }> {
598598
try {
599599
// Build query parameters
@@ -609,7 +609,7 @@ export async function searchMovies(searchParams: {
609609
if (searchParams.cast) queryParams.append('cast', searchParams.cast);
610610
queryParams.append('limit', limit.toString());
611611
queryParams.append('skip', skip.toString());
612-
if (searchParams.search_operator) queryParams.append('search_operator', searchParams.search_operator);
612+
if (searchParams.searchOperator) queryParams.append('searchOperator', searchParams.searchOperator);
613613

614614
const response = await fetch(`${API_BASE_URL}/api/movies/search?${queryParams}`, {
615615
method: 'GET',

mflix/server/java-spring/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ PORT=3001
1515
# For multiple origins, separate with commas
1616
CORS_ORIGIN=http://localhost:3000
1717

18+
# Optional: Enable MongoDB Search tests
19+
# Uncomment the following line to enable Search tests
20+
# ENABLE_SEARCH_TESTS=true

mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/service/MovieService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public interface MovieService {
8585

8686
/**
8787
* Finds similar movies using vector search on plot embeddings.
88-
* Demonstrates MongoDB Atlas Vector Search.
88+
* Demonstrates MongoDB Vector Search.
8989
*
9090
* @param movieId ID of the movie to find similar movies for
9191
* @param limit Maximum number of similar movies to return (default: 10, max: 50)

mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/service/MovieServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ public List<Movie> findSimilarMovies(String movieId, Integer limit) {
759759
.append("index", "plotEmbeddingIndex")
760760
.append("path", "plot_embedding")
761761
.append("queryVector", plotEmbedding)
762-
.append("numCandidates", resultLimit * 10)
762+
.append("numCandidates", resultLimit * 20) // We recommend searching 20 times higher than the limit to improve result relevance
763763
.append("limit", resultLimit + 1) // +1 to exclude the source movie
764764
);
765765

@@ -847,7 +847,7 @@ public List<VectorSearchResult> vectorSearchMovies(String query, Integer limit)
847847
.append("index", "vector_index")
848848
.append("path", "plot_embedding_voyage_3_large")
849849
.append("queryVector", queryVector)
850-
.append("numCandidates", resultLimit * 15) // Search more candidates for better results
850+
.append("numCandidates", resultLimit * 20) // We recommend searching 20 times higher than the limit to improve result relevance
851851
.append("limit", resultLimit)
852852
);
853853

0 commit comments

Comments
 (0)