Skip to content

Instantly share code, notes, and snippets.

@JustAyush
Created June 24, 2019 23:15
Show Gist options
  • Save JustAyush/649c2b2194e3789a9a8026532532aef8 to your computer and use it in GitHub Desktop.
Save JustAyush/649c2b2194e3789a9a8026532532aef8 to your computer and use it in GitHub Desktop.
# -----------This works!-------------------------------
book_search_variable= searchString
y=mydb['bookDataset'].find({"Book-Title":{"$regex":book_search_variable}}).limit(5)
bookSearched=list(y)
print(bookSearched)
#----------------trying to change Book-Author to bookAuthor-----------------------------
#----------------didn't work---------------------------
#-----------book_search_data = [] always------------------------
book_search_variable= searchString
y=mydb['bookDataset'].find({"Book-Title":{"$regex":book_search_variable}}).limit(5)
bookSearched=list(y)
w=mycol.aggregate([{"$match":{"Book-Title":{"$in":bookSearched}}},
{"$project":{'_id':0,'ISBN':'$ISBN', 'bookTitle':'$Book-Title','bookAuthor':'$Book-Author','genres':'$genres','imageURL':'$Image-URL','averageRating':'$average_rating','publicationYear':'$publication_year','description':'$description'} }])
book_search_data = list(w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment