Agentes de texto a consulta con MongoDB y LangGraph
Apoorva Joshi
Senior AI/ML Developer Advocate, MongoDB








Consulta SQL de ejemplo
SELECT *
FROM table
WHERE year>=1950
LIMIT 5
Ejemplo de entrada tipo JSON
{ "$and": [
{"year": {"$gte": 1990}},
{"year": {"$lt": 2000}}
]
}
Métodos de consulta en MongoDB
.find(), .insert(), .update(), .delete()| _id | Título | Año de estreno | Reparto | Géneros |
|---|---|---|---|---|
| 573a1396f29313caabce3d17 | Larks on a String | 1990 | [Rudolf Hrusènskè, Vlastimil Brodskè] | [Comedia, Drama, Romance] |
| 573a1398f29313caabceab72 | The Witching of Ben Wagner | 1990 | [Sam Bottoms, Harriet Hall, Bettina Rae, Justin Gocke] | [Familiar] |
| ... | ... | ... | [...] | [...] |
query = {"genre": "Romance"}
query = {"genre": "Romance"}
| _id | Título | Año de estreno | Reparto | Géneros |
|---|---|---|---|---|
| 573a1390f29313caabcd6377 | Wild and Woolly | 1917 | [Douglas Fairbanks, Eileen Percy, Calvert Carter, Charles Stevens] | [Comedia, Western, Romance] |
| 573a1391f29313caabcd70b4 | The Four Horsemen of the Apocalypse | 1921 | [Pomeroy Cannon, Josef Swickard, Bridgetta Clark, Rudolph Valentino] | [Drama, Romance, Bélico] |
query = { "$and": [
{"year": {"$gte": 1990}},
{"year": {"$lt": 2000}}
]
}
query = { "$and": [
{"year": {"$gte": 1990}},
{"year": {"$lt": 2000}}
]
}
| _id | Título | Año de estreno | Reparto | Géneros |
|---|---|---|---|---|
| 573a1396f29313caabce3d17 | Larks on a String | 1990 | [Rudolf Hrusènskè, Vlastimil Brodskè] | [Comedia, Drama, Romance] |
| 573a1398f29313caabceab72 | The Witching of Ben Wagner | 1990 | [Sam Bottoms, Harriet Hall, Bettina Rae, Justin Gocke] | [Familiar] |

db.<collection>.aggregate([
{stage-1},
{stage-2},
{stage-3},
{stage-4},
])
query = []
query = [{ "$sort": { "released": -1 } },]
releasedquery = [{ "$sort": { "released": -1 } },{ "$limit": 5 },]
released5 resultadosquery = [{ "$sort": { "released": -1 } },{ "$limit": 5 },{ "$project": { "title": 1, "_id": 0 } }]
released5 resultados"title"query = [{ "$sort": { "released": -1 } },{ "$limit": 5 },{ "$project": { "title": 1, "_id": 0 } }]
released5 resultados"title"| Título |
|---|
| The Treasure |
| Knight of Cups |
| Sand Castles |
| Shut In |
| Dègradè |
| _id | Título | Año de estreno | Reparto | Géneros |
|---|---|---|---|---|
| 573a1396f29313caabce3d17 | Larks on a String | 1990 | [Rudolf Hrusènskè, Vlastimil Brodskè] | [Comedia, Drama, Romance] |
| 573a1398f29313caabceab72 | The Witching of Ben Wagner | 1990 | [Sam Bottoms, Harriet Hall, Bettina Rae, Justin Gocke] | [Familiar] |
| ... | ... | ... | [...] | [...] |
query = [{ "$unwind": "$genres" },{ "$group": { "_id": "$genres", "numMovies": { "$sum": 1 } }},{ "$match": { "numMovies": { "$gte": 50 } } }]
| Género | Recuento |
|---|---|
| Drama | 12385 |
| Comedia | 6532 |
| Romance | 3318 |
| Crimen | 2457 |
| Thriller | 2454 |
| ... | ... |
Etapas del pipeline
$match, $group, $facet, $geoNear, $lookup, $merge, $search, $sort...Operadores
$eq, $gt, $gte, ...$add, $multiply, $divide...$push, $reduce, ...$toUpper, $toLower, ...$dateAdd, $dateDiff, ...Agentes de texto a consulta con MongoDB y LangGraph