您可以使用以下功能在更简单的更新操作中更新投票
集合。
假设投票
集合文档strcture是:
{
_id: ObjectId("62c59379ed72ad7e8e85a8d7"),
user_id: 12,
post_id: "Complex Update",
vote_value: 1 // this can be 0, 1 (upvote) or -1 (downvote) values only.
}
更新操作逻辑和函数:
如果不存在文档 - >
- 创建新文档,其中三个文档字段(
fote_value
将为1
或-1
)。
如果存在文档 - >
- 如果upvote& amp;现有的投票值== 1,已经投票,发送消息“不能再次投票”。没有更新。
- 如果upvote& amp;现有投票值== -1,将投票值更新为0(零)。
- 如果upvote& amp;现有投票值== 0,将投票价值更新为1
- 。现有投票值== 1,将投票值更新为0(零)。
- 如果降级& amp;现有的投票值== -1,已经被投票,发送消息“不能再次投票”。没有更新。
- 如果降级& amp;现有投票值== 0,将投票值更新为-1。
该函数的输入是三个变量: userId
, postid
和 fotevalue
(值是 1
for UpVote和 -1
用于下调的投票)。请注意,如果 POST_ID
和 user_id
(一起)不存在 post_id
(请注意使用 UPSERT
标志)。
function updateVote(postid, userid, votevalue) {
// Validate for input values...
// Validate for votevalue == 1 or -1
// Convert votevalue to an integer, if required
var result = db.test.findOneAndUpdate(
{ post_id: postid, user_id: userid },
[
{
$set: {
vote_value: { $ifNull: [ "$vote_value", 0 ] }
}
},
{
$set: {
vote_value: {
$switch: {
branches: [
{ case: { $and: [ { $eq: [ votevalue, 1 ] }, { $eq: [ "$vote_value", -1 ] } ] }, then: 0 },
{ case: { $and: [ { $eq: [ votevalue, 1 ] }, { $eq: [ "$vote_value", 0 ] } ] }, then: 1 },
{ case: { $and: [ { $eq: [ votevalue, -1 ] }, { $eq: [ "$vote_value", 0 ] } ] }, then: -1 },
{ case: { $and: [ { $eq: [ votevalue, -1 ] }, { $eq: [ "$vote_value", 1 ] } ] }, then: 0 },
],
default: "$vote_value"
}
}
}
},
],
{
projection: { vote_value: 1 },
upsert: true
}
)
if (result === null) {
return "created new document";
}
if (votevalue === 1 && result.vote_value === 1) {
return "cannot upvote again";
}
else if (votevalue === -1 && result.vote_value === -1) {
return "cannot downvote again";
}
else {
return "voted successfully";
}
}
注意:
- JavaScript功能代码适用于
Mongosh
(或mongo
shell)。 - 这需要MongoDB v4.2或更高(使用聚合管道的更新)。
Promise.All
的想法是将作为参数作为...承诺的数组?无论如何,这应该起作用(测试)。
import fetch from 'node-fetch';
import DomParser from 'dom-parser';
var parser = new DomParser();
const urlsData = ['http://www.ynet.co.il/Integration/StoryRss2.xml', 'http://www.ynet.co.il/Integration/StoryRss544.xml'];
var total = [];
Promise.all(urlsData.map(u => fetch(u)
.then(response => response.text())
.then(str => parser.parseFromString(str, "text/xml"))
.then(data => total.push(...data.getElementsByTagName('item'))))
).then(() => {
console.log(total)
})
只有第3层开关能够显示直接连接到它们的设备的IP地址。您的 sg-1008d 只是一个不受管理的开关,它将无法显示连接到其的设备的MAC或IP地址。您将能够通过运行网络工具(例如或通过查看路由器的连接设备列表。但这不会向您显示设备在开关中连接的端口。
修复程序
您必须将Express Server作为静态保存的静态文件JF作为静态文件
(在生产中避免,因为它们可能会在重新部署上删除,因此应避免使用图像)。
为此,假设图像存在于 public/images
中,则应添加以下行
app.use(express.static('public'))
, public/images/1.png
应该在http:/ /localhost:8000/images/1.png
为什么需要这?
Essential,Express仅服务于您在路由中默认情况下生成的响应。因此,您需要要求Express将“公共”中的文件作为静态文件(按原样)提供。
Note - Express在静态目录中查找文件,因此静态目录的名称不是URL的一部分。
参考
https://expressjs.coms.com/en/en/starter/static-files.html a>
使用两个INT的滴定方法是一种实例方法,您正在尝试不先创建对象实例的情况。
为什么编译器应该接受?我高度怀疑,在任何先前的JDK中,其行为都不同。
Create the configmap from a file.
Just create a sample file like ui.properties
example:
cat ui.properties
1. name=x
2. rollno=y
Command to create a configmap from above file
kubectl create configmap ui-configmap --from-file=ui.properties
Verify the data.
kubectl get configmap ui-configmap -o yaml
apiVersion: v1
kind: ConfigMap
metadata:
creationTimestamp: <>
name: ui-configmap
namespace: default
data:
name: x
role: y
Typescript旨在通过 声明合并 a>:
您可能还熟悉创建功能的JavaScript练习,然后通过将属性添加到功能中进一步扩展功能。 Typescript使用声明合并以类型安全的方式构建这样的定义。
声明合并的声明让我们说某物既是功能又是一个名称空间(内部模块):
function f() { }
namespace f {
export var someValue = 3;
}
这可以保留键入,并让我们同时编写 f()
和 f.somevalue
。在编写 .d.t.ts
为现有JavaScript代码的文件时,请使用 neclare
:
declare function f(): void;
declare namespace f {
export var someValue: number;
}
将属性添加到功能中通常是一个令人困惑或意外的模式,因此请避免它,但是,使用或转换较旧的JS代码时可能有必要。这是将内部模块(名称空间)与外部混合的唯一时间之一。
函数或库无法实现所需的输出,因此始终有一种通过逻辑来实现结果的方法。
print('abc')
a="\n"*10
x= input(a+'Enter here :')
print(x)
。
=SUMPRODUCT(--(MMULT(--ISNUMBER(SEARCH({"Red","Green","Blue"},A1:A6)),ROW($ZZ$1:INDEX($ZZ:$ZZ,COLUMNS({"Red","Green","Blue"})))^0)>0))
所有版本 将,
更改为定界符,以使其成为本地设置中的水平数组。
而且,不确定这一点,但是在较旧的版本中,这可能需要使用CTRL换档 - 输入编辑模式时输入。
您可以使用 row_number()
来标识所需的行。然后,过滤行很容易。例如:
select *
from (
select t.*,
row_number() over(
partition by study_spec_no, status
order by version_no desc
) as rn
from t
where status in ('New', 'Released')
) x
where rn = 1
edit
如果要使用谓词注释排除行,则不是null或version_description nes null
您可以 and
它到<<<代码>其中括号中的子句,如以下内容
where status in ('New', 'Released')
and (notes is not null OR version_description is not null)
您没有从 uisearchbardelegate
中实现任何方法,因为您的 searchclients
函数未正确命名。您将需要将其重命名为实际上从委托协议实现了该函数。
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
Swift中很少有nitpicks
- 从较小的字母开始命名属性,
var companyID = ""
var companyName = ""
var clientList = [Client]()
var filteredArray = [Client]()
let urlService = "https://fetch.php"
- 您可以跳过每个
self。
在引用声明类型范围内的属性或功能时,您将作为前缀添加为前缀。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
companyID = filteredArray[indexPath.row].companyID
companyName = filteredArray[indexPath.row].name
}
- 当协议符合使用扩展符合时,它的清洁程度要大得多,因此代码很好地分开,并且它们不会相互混合。
extension TableViewController: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
//let text: String = self.searchClients.text ?? ""
print("search for \(searchText)")
filteredArray = []
if searchText == "" {
filteredArray = clientList
} else {
filteredArray = clientList.filter { item in
item.name.lowercased().contains(searchText.lowercased())
}
}
print(filteredArray)
tableView.reloadData()
}
}
您之所以遇到的原因是因为可能无法设置环境变量(TypeScript无法知道这一点,因为它仅在编译时起作用,而在运行时不起作用),因此您需要窄环境变量 string
。您可以手动执行它,或使用inden-in ok ok ok 断言函数来自节点:
import {ok} from 'assert/strict';
ok(
process.env.DB_CONNECTION,
'DB_CONNECTION environment variable is not defined',
);
// Now `process.env.DB_CONNECTION` is guaranteed not to be `undefined`
// connect to DB
mongoose.connect(
process.env.DB_CONNECTION,
{
useUnifiedTopology: true,
useNewUrlParser: true,
useCreateIndex: true,
},
() => {
console.log('connected to db');
}
);
您可以使用char(60)类型。这是与二进制旁边提出的(64)。参考:用于使用哪种数据类型哈希密码字段和多少长度?
如果您的哈希没有编码为base64或十六进制或其他,请使用
bytea
。You can use CHAR(60) type. This is suggested alongside BINARY(64). Reference: What data type to use for hashed password field and what length?
If your hash is not encoded as Base64 or hex or whatever, use
BYTEA
.yugabytedb中模仿二进制的数据类型(64)