I have built an application that stores all of my data in a MongoDB with thousands of entries. Now I want to query it from an HTML page. I have been able to successfully load the data with a button click, but I am unsure as to how to write a query for it. In standard MySQL, I could do something like "SELECT * from dbname where initials = "AA" and sector = "ECHO" " which are fields in the database. I have these fields in my object as well. How would I write the query to achieve the results similar to the MySQL statement above?
This is a sample of the array of objects data being returned:
[{_id: {$oid: "58306ce77df6dc1268c87142"}, cjs: "ZV", comment: null, current: false, duration: 50,…},…]
[0 … 99]
0:{_id: {$oid: "58306ce77df6dc1268c87142"}, cjs: "ZV", comment: null, current: false, duration: 50,…}
_id:{$oid: "58306ce77df6dc1268c87142"}
cjs:"ZV"
comment:null
current:false
duration:50
duration_string:null
error:null
expires_at:"2021-10-04T00:41:34.000Z"
fde_id_final:"778152728"
fde_id_initial:"778134619"
function:"SAT.IN"
initials:"AA"
json_class:"SatTransaction"
name:"Al Albert"
ot:false
position:"RDR"
quality:null
satin:"2016-10-05T00:41:34.000Z"
satout:"2016-10-05T01:32:20.000Z"
sector:"ECHO"
shift_date:"2016-10-04T00:00:00.000Z"
shift_duration:508
shift_duration_string:null
shift_end:58
shift_start:990
trainee:false
1:{_id: {$oid: "58306ce77df6dc1268c87144"}, cjs: "FY", comment: null, current: false, duration: 51,…}
And this is my basic HTML where I use a button to load the entire JSON file:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.getJSON("http://maccdx170131:4567/api/v1/sat", function(result){
});
});
});
</script>
</head>
<body>
<button>Get JSON data</button>
<div></div>
</body>
</html>
Thanks for any help or advice!!