小编FOR*_*RAN的帖子

如果在其中一个文件上失败,如何退出find -exec

我想运行命令

find some/path -exec program \{} \; 
Run Code Online (Sandbox Code Playgroud)

但我希望find命令尽快退出命令

 program \{}
Run Code Online (Sandbox Code Playgroud)

找不到任何文件失败.

有一个简单的方法吗?

bash exec find exit

16
推荐指数
3
解决办法
3647
查看次数

Mongoose模式要求数组可以为空

我有这个架构

var StuffSchema = new mongoose.Schema({
    _id: { type: String, required: true, unique: true },
    name: { type: String, required: true }
});

mongoose.model('Stuff', StuffSchema);
Run Code Online (Sandbox Code Playgroud)

工作良好.

现在我需要添加包含此内容的另一个模式"Cargo"

mystuff: { type:[String], ref: 'Stuff', required:true},
Run Code Online (Sandbox Code Playgroud)

也就是说,我希望mystuff包含Stuff的id数组,但是在运行此代码时,这会因验证错误而失败

mongoose.model('Cargo').create( some data...)
Run Code Online (Sandbox Code Playgroud)

如果我为mystuff字段使用空数组.如果我将Cargo架构更改为,它似乎有效

mystuff: { type:[String], ref: 'Stuff'},
Run Code Online (Sandbox Code Playgroud)

但我希望mystuff字段是必需的并允许空数组

我该怎么做才能实现这一目标?

arrays validation mongoose required

11
推荐指数
1
解决办法
6651
查看次数

Postgres 函数与文本数组并选择查询中的位置

我需要创建一个像这样的函数(缩小到最小值),在其中发送应该匹配的字符串数组。但我无法使查询工作。

create or replace function bar(x text[]) returns table (c bigint) language plpgsql as $$
begin
    return query select count(1) as counter from my_table where my_field in (x);
end;$$;
Run Code Online (Sandbox Code Playgroud)

并这样称呼它

select * from bar(ARRAY ['a','b']);
Run Code Online (Sandbox Code Playgroud)

我可以尝试让参数 x 成为单个文本字符串,然后使用类似的东西

return query execute 'select ... where myfield in ('||x||')';
Run Code Online (Sandbox Code Playgroud)

那么我该如何让它以数组形式使用参数呢?与让参数为字符串相比,这会更好还是更差?

arrays postgresql plpgsql where-clause

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

标签 统计

arrays ×2

bash ×1

exec ×1

exit ×1

find ×1

mongoose ×1

plpgsql ×1

postgresql ×1

required ×1

validation ×1

where-clause ×1