Program 10_WM
Program 10_WM
"category": "Electronics"
}
{
"category": "Electronics"
}
{
"category": "Audio"
In MongoShell
>use TextDB
Output:
Define the Aggregation Pipeline
Now, create an aggregation pipeline to perform the text search and process the results. Below
is an example pipeline:
db.catalog.aggregate([
// Stage 1: Match documents containing the search term
{
$match: {
$text: { $search: " Apple iPhone 14" }
}
},
// Stage 2: Project only required fields
{
$project: {
_id: 0,
name: 1,
description: 1,
category: 1
Output: