小编Red*_*ant的帖子

$ addToSet一个对象到mongoose中的数组

我有一个存储少量产品文档的集合.在文档中,有一个数组evaluation用于存储用户对产品的价格评估对象.

以下是用户对象的示例:

var data = {user_id:90,price:400}
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我是否有可能在evaluation阵列上执行"插入重复更新" ?我试过了$addToSet,但是当一个对象被推入时evaluation,有一个_id属性被添加到用户对象,即使我在模型中没有它,如下所示:

{
  "_id": 54b13f52604fc5d242d4aa68,
  "__v": NumberInt(0),
  "evaluation": [
    {
      "price": NumberInt(14616),
      "user_id": NumberInt(91),
      "_id": ObjectId("54b13f5e604fc5d242d4aa6b") // Why is it added?
    },
    {
      "price": NumberInt(16211),
      "user_id": NumberInt(92),
      "_id": ObjectId("54b140d1604fc5d242d4aa74") //
    }
  ],
  "product": [
   {
      "title": "ABC",
      "model_id": "382",
      "id": "513",
      "category": "1",
      "src": "xxx.jpg"
    }
  ],
  "timestamp":ISODate("2015-01-10T15:03:46.310Z")
}
Run Code Online (Sandbox Code Playgroud)

那是如何$addToSet使用id字段来检查重复的对象?

model.js

var evaluation = new mongoose.Schema({
       product:[],
       timestamp : { type : …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb node.js

5
推荐指数
1
解决办法
6137
查看次数

如何使用phpredis在PHP中删除多个具有相同模式的redis键?

通过使用phpredis,我在分页中保存了一些数据,如下所示:

   review/itemA/1
   review/itemA/2 
Run Code Online (Sandbox Code Playgroud)

其中12是页码。我在文档中读到您可以使用通配符来检索多个键。

$allKeys = $redis->keys('*');   // all keys will match this.
$keyWithUserPrefix = $redis->keys('user*');
Run Code Online (Sandbox Code Playgroud)

但是,当有人发布新评论时,我是否也可以使用通配符删除所有旧密钥?我可以做这样的事情:

$redis->delete('review/itemA/*'); // or  $redis->delete('review/itemA*')
Run Code Online (Sandbox Code Playgroud)

然而它并没有奏效。

php redis phpredis

5
推荐指数
2
解决办法
2万
查看次数

convertFromHTML 是否支持 Draft.js 中的自定义块类型?

这是该问题的代码笔示例。

我添加了一个名为 的自定义块类型section,它将所选文本包装为红色。当您单击section编辑工具栏中的时,它工作正常。但是,当用于convertFromHTML渲染初始内容时,

const sampleMarkup = '<b>Bold text</b><br/>Section Testing:<section>dsasdasad</section><br/><i>Italic text</i>';

编辑器仍然将section类型视为unstyle类型。是否convertFromHTML支持用于初始渲染的自定义块类型?有解决方案吗?

代码:

      const {Editor,convertFromHTML,ContentState, EditorState,DefaultDraftBlockRenderMap, RichUtils} = Draft;

      const blockRenderMap = Immutable.Map({
    'section': {
        element: 'section'
    }
});

     const extendedBlockRenderMap = DefaultDraftBlockRenderMap.merge(blockRenderMap);

      class RichEditorExample extends React.Component {
        constructor(props) {
          super(props);
          const sampleMarkup =
  '<b>Bold text</b><br/>Section Testing:<section>dsasdasad</section><br/><i>Italic text</i>';

          const blocksFromHTML = convertFromHTML(sampleMarkup);
          const state = ContentState.createFromBlockArray(
            blocksFromHTML.contentBlocks,
            blocksFromHTML.entityMap
          );

          this.state = {editorState: EditorState.createWithContent(state)};

          this.focus = () => this.refs.editor.focus();
          this.onChange …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs draftjs

5
推荐指数
1
解决办法
1204
查看次数

PayPal-node-SDK`订阅开始日期应该大于当前日期`始终在上午12点之后发生

我住在香港,我总是在午夜之后得到这个沙盒paypal交易错误paypal.billingAgreement.execute().错误在下午消失,可能是因为paypal服务器所在的地方终于过了午夜.

{    name: 'SUBSCRIPTION_UNMAPPED_ERROR',
     message: 'Subscription start date should be greater than current date',
     information_link: 'https://developer.paypal.com/docs/api/payments.billing-agreements#errors',
     debug_id: 'd2e618eef4162',
     httpStatusCode: 400
 },
Run Code Online (Sandbox Code Playgroud)

我知道这是沙盒环境的时区问题,但我无法弄清楚如何解决它.

我的结算协议是根据PayPal-node-SDK中的示例创建的

process.env.TZ = 'utc';
var isoDate = new Date();
isoDate.setSeconds(isoDate.getSeconds() + 4);
isoDate.toISOString().slice(0, 19) + 'Z';

var billingAgreementAttributes = {
    "start_date": isoDate,
    /..../
}
Run Code Online (Sandbox Code Playgroud)

我已将TZ节点中的环境变量设置为utc;

我用来登录和订阅的沙箱帐户的时区设置:

在此输入图像描述

我也试过不同的区域,Eastern Time但它没有效果.

paypal paypal-subscriptions paypal-sandbox node.js paypal-rest-sdk

5
推荐指数
1
解决办法
454
查看次数

apollo graphql 响应数据中未显示“Extensions”字段

这是一个可重现的示例在http://localhost:4000/graphql上运行app.js并导航游乐场

您可以运行如下查询:

query RecipeQuery{
  recipe(title:"Recipe 2"){
    description
  }
}
Run Code Online (Sandbox Code Playgroud)

问题:

我需要extensions响应数据中现场的调试信息。我说的是这个extensions领域:

  "data":{....},
  "extensions": {
    "tracing": {}
    "cacheControl":{}
  }
Run Code Online (Sandbox Code Playgroud)

但实际上,我只获取数据字段:

  "data":{....}
Run Code Online (Sandbox Code Playgroud)

我已经在 apollo 服务器配置中启用了tracing和,但该字段仍然被排除在响应数据中。我怎样才能取回数据?cacheControlextensionsextensions

以下是阿波罗引擎的启动方式:

const expressApp = express();

const server = new ApolloServer({
    schema,
    tracing: true,
    cacheControl: true,
    engine: false, // we will provide our own ApolloEngine
});

server.applyMiddleware({ app: expressApp });

const engine = new ApolloEngine({
    apiKey: "YOUR_ID",

});

engine.listen(
    {
        port,
        expressApp,
        graphqlPaths: …
Run Code Online (Sandbox Code Playgroud)

node.js express apollo graphql apollo-server

5
推荐指数
1
解决办法
1937
查看次数

修复 Argo CD 中的不同步警告 - 无法忽略可选的“preserveUnknownFields”字段

Argo CD 显示 linkerd(由 Helm 安装)中的两个项目不同步。preserveUnknownFields: false这些警告是由该部分中的可选选项引起的spec

Trafficsplits.split.smi-spec.io 在此输入图像描述

在此输入图像描述

serviceprofiles.linkerd.io

在此输入图像描述

在此输入图像描述

但我无法弄清楚如何忽略清单ignoreDifferences中使用的差异Application。json路径/spec/preserveUnknownFields不起作用。是因为左侧版本中不存在字段preserveUnknownFields吗?


apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: linkerd
  namespace: argocd
spec:
  destination:
    namespace: linkerd
    server: https://kubernetes.default.svc
  project: default
  source:
    chart: linkerd2
    repoURL: https://helm.linkerd.io/stable
    targetRevision: 2.10.1
 syncPolicy:
    automated: {}
  ignoreDifferences:
     - group: apiextensions.k8s.io/v1
       name: trafficsplits.split.smi-spec.io
       kind: CustomResourceDefinition
       jsonPointers:
         - /spec/preserveUnknownFields
     - group: apiextensions.k8s.io/v1
       name: trafficsplits.split.smi-spec.io
       kind: CustomResourceDefinition
       jsonPointers:
         - /spec/preserveUnknownFields
Run Code Online (Sandbox Code Playgroud)

jsonpath kubernetes jsonpointer linkerd argocd

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

在为每个组件文件夹使用index.ts桶文件后,从Vite.js收到大量“块之间的循环依赖”警告

阅读https://github.com/alan2207/bulletproof-react/blob/master/docs/project-struct.md后。我已经开始重新组织使用代码分割的反应站点的文件夹结构。组件文件夹如下所示:

src
  client
    product
       product-list
         index.ts
         product-list.tsx
         product-list-item.tsx
               
   
Run Code Online (Sandbox Code Playgroud)

index.ts 是一个重新导出 ProductList 组件的桶文件

// product-list/index.ts
export { ProductList } from './product-list';
export type { ProductListProps } from './product-list';
Run Code Online (Sandbox Code Playgroud)

但在构建过程中我从 Vite 收到了很多这样的警告:

Export "ProductList" of module "src/client/product/product-list/product-list.tsx" was
reexported through module "src/client/product/product-list/index.ts" while both 
modules are dependencies of each other and will end up in different chunks by current 
Rollup settings. This scenario is not well supported at the moment as it will produce 
a circular dependency between chunks and …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs vite

5
推荐指数
0
解决办法
1166
查看次数

如何在PHP中传递带有ob_start参数的回调函数?

我一直在关注这个教程上的缓存功能.我遇到了传递回调函数cache_page()的问题ob_start.如何传递cache_page()沿两个paramters $mid$pathob_start,沿东西线

  ob_start("cache_page($mid,$path)");
Run Code Online (Sandbox Code Playgroud)

当然以上都行不通.这是示例代码:

$mid = $_GET['mid'];

$path = "cacheFile";

define('CACHE_TIME', 12);

function cache_file($p,$m)
{
    return "directory/{$p}/{$m}.html";
}

function cache_display($p,$m)
{
    $file = cache_file($p,$m);

    // check that cache file exists and is not too old
    if(!file_exists($file)) return;

    if(filemtime($file) < time() - CACHE_TIME * 3600) return;

    header('Content-Encoding: gzip');

    // if so, display cache file and stop processing
    echo gzuncompress(file_get_contents($file));

    exit;
}

  // write to cache file
function cache_page($content,$p,$m) …
Run Code Online (Sandbox Code Playgroud)

php caching ob-start

4
推荐指数
1
解决办法
1390
查看次数

将额外参数传递给reactjs中的onChange Listener

我看到一个onChange监听器通常没有额外的参数e.

handleOnChange(e) {
   this.setState({email: e.target.value});
}
Run Code Online (Sandbox Code Playgroud)

但是仍然可以通过额外的论点吗?像这样:

handleOnChange(e,key) {
   this.setState({[key]: e.target.value});
}
Run Code Online (Sandbox Code Playgroud)

我修改了这个线程中的代码来做一个例子

class FormInput extends React.Component{

    consturctor(props){
       super(props);
       this.state = {email:false,password:false}
    }

    handleOnChange(e,key) {
       this.setState({[key]: e.target.value});
    }

    render() {
          return 
            <form>
              <input type="text" name="email" placeholder="Email" onChange={this.handleOnChange('email')} />
              <input type="password" name="password" placeholder="Password" onChange={this.handleOnChange('password')}/>
              <button type="button" onClick={this.handleLogin}>Zogin</button>
            </form>;
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 reactjs

4
推荐指数
1
解决办法
1787
查看次数

在redux中没有使用reactjs定义调度

我想知道为什么点击表格行仍然会给我未定义的调度错误导致Uncaught TypeError: dispatch is not a function.我一直在关注这篇文章,试图解决问题,但到目前为止还没有成功.

ListingTable.js

import Table from 'grommet/components/Table';
import React from 'react';
import {remove, add} from '../action/ListAction';
import {connect} from 'react-redux'

let createHandlers = function(dispatch) {
    let onClick = function(item) {
        dispatch(add(item)) <<== undefined!!!!
    };
    return {
        onClick
    };
};
export class ListingTable extends React.Component {

    constructor(props) {
        super(props);
        this.handlers = createHandlers(this.props.dispatch);
    }
    render() {
        return <Table>
                <tbody>
                {
                    this.props.data.map((item, key)=>
                        (
                            // Undefined Error!!!!
                            <tr onClick={()=> this.handlers.onClick(item)} key={key}>

                                <td>{item.user_name}</td>
                                <td>{item.name}</td>
                                <td>{item.url}</td> …
Run Code Online (Sandbox Code Playgroud)

javascript flux ecmascript-6 reactjs redux

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