If you want to find an element inside of a list in
Now if you want to find a document that has the value of
#mongodb #mongo #find #list #array
MongoDB
document you can use the simple find command. Let's say you have the below documents:[{
"food": "Ghorme",
"creation_date": "2017-10-12 12:00:00"
"rates": ["bad", "so_so", "not_bad", "mmmm"]
},{
"food": "Kebab",
"creation_date": "2017-10-07 22:10:00"
"rates": ["great", "not_bad", "great", "great"]
}]
Now if you want to find a document that has the value of
bad
in rates
, you just use the below find
query:db.foods.find({rates: "bad" }).pretty()
#mongodb #mongo #find #list #array
Array and loop in bash script
To define an array you can use a structure like below, be careful that we don't use comma in between:
dbs=( 'test1' 'test2' 'test3' )
Now to loop over the array elements use
for
:for your_db in ${dbs[@]}
do
echo $your_db
done
This is it!
#bash #scripting #for #loop #array