如何在MongoDB的嵌入式文档中添加字段?

时间:2017-05-04 16:14:18

标签: mongodb

我的文档如下:

 {
  first_name:"A",
  last_name:"B",
  subjects:
        {
          literature:"Eng",
          science:"Physics",
          //How can i add field here e.g., socialStudies:"History"
        }
  }   

这里,主题不是任何数组。其子文档中我想添加一个新字段。请帮忙

1 个答案:

答案 0 :(得分:1)

您可以使用点表示法进行简单设置。

class ProductPage extends Component {
  constructor() {
    super();
    this.peekClick = this.peekClick.bind(this);
    this.peekHide = this.peekHide.bind(this);

    this.state = {
      peekaboo: false
    };
  }

  peekClick = () => {
    this.setState({peekaboo: true});}

  peekHide = () => {
    this.setState({peekaboo: false});}

  render() {
    return (
      <div className="ProductPage">
        <div className="ProductPage-Left">
        {/* PROBLEM IS HERE */}
            <div className="leftViewTab" onBlur={this.peekHide}>
              {this.state.peekaboo ? (null) :
                (<div className="leftViewText" onClick={this.peekClick}>
                    View Store
              </div>)}
            </div>
        </div>