我具有以下文档结构:
import * as React from "react";
export default class Pagination extends React.Component {
constructor(props) {
super(props);
this.state = {
pages: this.findNumberOfPages()
};
this.findNumberOfPages = this.findNumberOfPages.bind(this)
}
componentDidMount() {
console.log(this.props);
}
componentDidUpdate(prevProps) {
if(prevProps.dataCount != this.props.dataCount){
this.setState({ pages: this.findNumberOfPages() });
}
}
findNumberOfPages() {
return Math.ceil(this.props.dataCount / 10);
}
renderPageNumbers = () => {
const numberOfPages = this.findNumberOfPages()
let pages = [];
for (let i = 1; i <= numberOfPages; i++) {
pages.push(<span key={i}>{i}</span>);
}
return pages;
};
render() {
return (
<>
{this.props.currentPage > 1 ? <span>Prev</span> : ""}
{this.renderPageNumbers()}
{this.props.currentPage < this.state.pages ? <span>Next</span> : ""}
</>
);
}
}
我想做的是每分钟选择所有文档,然后计算每个传感器的平均值并得到如下结果:
{
"_id": "5d2708ff79263ba40e54c08c",
"meta": {
"uid": "dd41ca10-a3c2-11e9-a1dd-fbec9d04cb25",
"firmware": "0.0.1",
"timestamp": "2019-07-11T10:01:35.264Z"
},
"sensors": [
{
"_id": "5d2708ff79263ba40e54c08e",
"name": "sensor1",
"value": 0.09050827850822706
},
{
"_id": "5d2708ff79263ba40e54c08d",
"name": "sensor2",
"value": 0.06592630654288716
}
]
}
多年使用关系数据库后,这有点令人困惑。