Ex - Mongo DB
Ex - Mongo DB
br
Exercícios A
Exercício B - Atlas Search Index
use sample_mflix
switched to db sample_mflix
show collections
comments
movies
sessions
theaters
users
db.movies.aggregate([
{
$search: {
"text": {
"query": "baseball",
"path": "plot"
}
}
},
{
$limit: 5
},
{
$project: {
"_id": 0,
"title": 1,
"plot": 1
}
}
])
{
plot: 'A trio of guys try and make up for missed opportunities in
childhood by forming a three-player baseball team to compete
against standard children baseball squads.',
title: 'The Benchwarmers'
}
{
plot: 'A trained chimpanzee plays third base for a minor-league
baseball team.',
title: 'Ed'
}
{
plot: 'A young boy is bequeathed the ownership of a professional
baseball team.',
title: 'Little Big League'
}
{
plot: 'Babe Ruth becomes a baseball legend but is unheroic to
those who know him.',
title: 'The Babe'
}
{
plot: 'The story of the life and career of the famed baseball
player, Lou Gehrig.',
title: 'The Pride of the Yankees'
}
db.movies.aggregate([
{
$search: {
"compound": {
"must": [ {
"text": {
"query": ["Hawaii", "Alaska"],
"path": "plot"
},
},
{
"regex": {
"query": "([0-9]{4})",
"path": "plot",
"allowAnalyzedField": true
}
} ],
"mustNot": [ {
"text": {
"query": ["Comedy", "Romance"],
"path": "genres"
}
},
{
"term": {
"query": ["Beach", "Snow"],
"path": "title"
}
} ]
}
}
},
{
$project: {
"title": 1,
"plot": 1,
"genres": 1,
"_id": 0
}
}
])
{
plot: 'A modern aircraft carrier is thrown back in time to 1941
near Hawaii, just hours before the Japanese attack on Pearl
Harbor.',
genres: [
'Action',
'Sci-Fi'
],
title: 'The Final Countdown'
}
{
plot: "Follows John McCain's 2008 presidential campaign, from his
selection of Alaska Governor Sarah Palin as his running mate to
their ultimate defeat in the general election.",
genres: [
'Biography',
'Drama',
'History'
],
title: 'Game Change'
}
{
plot: 'A devastating and heartrending take on grizzly bear
activists Timothy Treadwell and Amie Huguenard, who were killed in
October of 2003 while living among grizzlies in Alaska.',
genres: [
'Documentary',
'Biography'
],
title: 'Grizzly Man'
}
{
plot: 'Truman Korovin is a lonely, sharp-witted cab driver in
Fairbanks, Alaska, 1980. The usual routine of picking up fares and
spending his nights at his favorite bar, the Boatel, is
disrupted ...',
genres: [
'Drama'
],
title: 'Chronic Town'
}
db.movies.aggregate([
{
$search: {
"text": {
"query": "The Count of Monte Cristo",
"path": { "value": "title", "multi": "keywordAnalyzer" }
}
}
},
{
$project: {
"title": 1,
"year": 1,
"_id": 0
}
}
Error: clone(t={}){const r=t.loc||{};return e({loc:new
Position("line"in r?r.line:this.loc.line,"column"in r?
r.column:...<omitted>...)} could not be cloned.
db.movies.aggregate([
{
$search: {
"text": {
"query": "The Count of Monte Cristo",
"path": { "value": "title", "multi": "keywordAnalyzer" }
}
}
},
{
$project: {
"title": 1,
"year": 1,
"_id": 0
}
}
])
{
title: 'The Count of Monte Cristo',
year: 1954
}
{
title: 'The Count of Monte Cristo',
year: 1934
}
{
title: 'The Count of Monte Cristo',
year: 1998
}
Exercícios 2A