小编Nar*_*Nar的帖子

Mongoose:.findById 不是函数

我有 2 个不同的模型 User 和 Leave,我想对其进行设置,以便每当删除休假时,该休假也将从用户文档中的叶子数组中提取。

用户模型:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const muv = require('mongoose-unique-validator');
const Leave = require('./leave');
const { ObjectID } = require('mongodb');

var schema = new Schema({
  fullName: {
    type: String,
    required: true,
    unique: true
  },
  leaveCredits: {
    type: Number
  },
  filedLeaves: [{
    type: Schema.Types.ObjectId,
    ref: 'Leave'
  }]
}, {
  usePushEach: true
});

schema.plugin(muv);

schema.pre('remove', function (next) {
  let user = this;
  let toDelete = [];
  user.filedLeaves.forEach(function(item) {
    Leave.findByIdAndRemove(new ObjectID(item), (err, succ) => …
Run Code Online (Sandbox Code Playgroud)

mongoose node.js express

3
推荐指数
1
解决办法
3270
查看次数

Reactjs:将相同的道具传递给多个组件

我对 reactjs 有点陌生,我正在尝试做一些清理工作。我想知道如何为新上下文 api 提供的道具使用传播属性?<Today />并且<All />基本上会使用相同的道具,我认为它看起来很凌乱。

以下是我想要清理的行:

     <ResultsProvider>
        <ResultsContext.Consumer>
          {(val) => (
            <Switch>
              <Route exact path={'/'} render={ (props) =>
                  <Today
                    results={val.results}
                    loading={val.loading}
                    viewTicket={val.viewTicket}
                    formatStatus={val.formatStatus}
                    fetchData={val.fetchData}
                    formatDate={val.formatDate}
                    sortResults={val.sortResults}
                    formatTitle={val.formatTitle}
                  />
              }/>
              <Route path={'/week'} component={Week} />
              <Route path={'/all'} render={ (props) => 
                  <All
                    results={val.results}
                    loading={val.loading}
                    viewTicket={val.viewTicket}
                    formatStatus={val.formatStatus}
                    fetchData={val.fetchData}
                    formatDate={val.formatDate}
                    sortResults={val.sortResults}
                    formatTitle={val.formatTitle}
                  />
              }/>
            </Switch>
          )}
        </ResultsContext.Consumer>
      </ResultsProvider>
Run Code Online (Sandbox Code Playgroud)

reactjs

2
推荐指数
1
解决办法
2903
查看次数

标签 统计

express ×1

mongoose ×1

node.js ×1

reactjs ×1