问题标签 [findandmodify]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
84 浏览

node.js - mongodb fndAndModify 的 nodejs 驱动程序

我有以下代码:

当我执行它时,返回错误消息“TypeError:undefined is not a function”,我真的无法弄清楚问题出在哪里。有人可以帮忙吗?

0 投票
1 回答
877 浏览

python - Python/R :如果 2 列在多行中具有相同的值,则将第 3 列中的值相加并平均第 4、第 5 和第 6 列

输入 :

输出:(将相同行的第 3 列值相加,并取第 4、第 5 和第 6 列中的所有值的平均值)

0 投票
1 回答
183 浏览

node.js - mongodb/nodejs/express/mongojs 和 findAndModify 的问题

目前正在做一个在线课程来学习一些 Node.js、Express 和 MongoDB。

在本课程中有一个 api 部分,他们教你做简单的事情,但我遇到了一个问题,课程视频显示他更新项目的名称,并且 api 可以更新更多字段,他的字段保持有值,我的字段实际上最终为空。

代码是

谁能向我解释一下,如果只更新名称,我如何避免说类别和描述最终为空?

0 投票
1 回答
916 浏览

php - 使用 PHP DOM Parser 查找和替换 HTML 中的字符串

如何使用原生 PHP DOM Parser 在 html 页面中查找和替换字符串?

要查找的示例字符串:"the <a href='site.com'>company</a> has been growing for the past 5 months";

例如,父级是一个完整的 HTML 页面,该字符串的直接前导可以是一个<div><p>例如..

该元素没有 id 或 class。是否仍然可以找到并操纵它?

没有任何东西可以识别字符串或其直接前任。只有确切的字符串,即 $search_string 包含的字符序列。

谢谢!

编辑:

$string_to_replace ="the <a href='site.com'>company</a> has been growing for the past 5 months";

$replacement_string ="<span class='someClass'>the <a href='site.com'>company</a> has been growing for the past 5 months";</span>

0 投票
2 回答
829 浏览

php - str_replace() 不适用于以下情况

我想用来str_replace()在 html 字符串周围放置 span 元素以突出显示它们。

&nbsp;但是,当字符串内部存在时,以下内容不起作用。我试过用替换&nbsp;' '但这没有帮助。


现场示例

您可以使用以下代码重新创建问题:

0 投票
0 回答
955 浏览

windows - 用另一个字符串批处理脚本替换 xml 中的值

我是批处理脚本的新手,我已经阅读了大量关于 SO 的帖子以找到答案,但似乎没有什么对我有用。我正在尝试读取一个 xml 文件并提取一些值,然后在同一个 xml 中找到一个字符串并用我构建的新字符串替换。我有以下代码,但是当我运行它时,我试图读取的 test.xml 被覆盖了。

在这里,我从 xml 中找到 URL 的值并将其存储到文本中

然后我拆分文本的值以提取 IP、端口和数据库名称并将它们存储在变量中

然后我从数据库名称中删除结束标签

然后我设置新旧变量来查找和替换文本

在下面的行中,我实际上逐行遍历 test.xml,找到旧文本并将其替换为新值,这是我执行上述所有操作的目的。

任何帮助表示赞赏。我已经花了大约 3 天的时间。

我的 test.xml 内容:

在上面的文件而不是 URL 属性中,我打算提取 IP、端口和 DB,并为所有三个值添加 xml 标记,就像在新字符串中一样。

0 投票
1 回答
1037 浏览

applescript - applescript search text file for multiple variable texts using surrounding "static" text

I am trying to create an applescript that will search for certain texts in a text file that are unfortunately variable (so every file I am supplied could have for instance of a different languages as the text that need finding GERMAN, FRENCH etc).

Then I need to replace this text with a user defined value. The text surrounding this is however a constant so,

For example the text file will contain order="GERMAN" where GERMAN needs to be replace by the users text.

I have written the code below where stringtofind is defined as GERMAN but what I really need is to define stringtofind as the value of whatever text appears between order=" and " .

The other issue, I have after this is that the file can in theory contain multiples of this value along with another value (so for instance a file could contain instances of order="GERMAN" along with instances of order="FRENCH" . In these cases I need that, user should be able to define different values for these (so all instance of GERMAN can be set to one replacement value and all instances of FRENCH can be set to a different value by the user)

Any assistance with this would be greatly appreciated.

0 投票
1 回答
1585 浏览

mongodb - 选择一个集合中 ID 与另一个集合中匹配的文档

我正在尝试对一个集合中的一组记录进行状态更新,其中一个 ID 存在于不同的集合中。

我想不出你会如何构造这样的查询,我相信我会将它添加到 finaAndModify 函数中,如下所示。

我想做的事情的要点是:

选择 db.raw_originBusinessData 中的记录,其中 db.std_sourceBusinessData 中存在 objectCycle_ID。

这是我要完成的脚本,如果 findAndModify 是错误的方法,请告诉我,非常感谢。

0 投票
1 回答
264 浏览

arrays - Mongodb get unique value from documents and add to array

I wanted to do a query to match documents in one collection with documents in another collection based upon a value which should be contained in both sets of documents but, as I have been informed that Mongo does not support a JOIN, I believe I can't do what I want in the way I want to.

My alternative method then is to insert a document into the collection (col1) where I want to do a query and update which contains an array of all the unique cycle number which are in the other collection (col2).

Collection 1 (Col 1)

Collection 2 (Col 2)

So I want to create a document in collection 1 which looks like this:

Now what I want to do is query ALL documents where cycle = cycles and update "status" to "processed". I believe I would do this with a findAndModify with multi : true but not entirely sure.

When finished, I will just simply delete any document in the Collection 1 where objectType is "Status Updater".

0 投票
1 回答
301 浏览

mongodb - 如何以 Spring 存储库抽象格式编写这些查询

1.考虑我有一个类有一个地图

如何使用其密钥从令牌映射中获取/删除单个令牌?该操作将导致文档的部分更新。

2. 在一个类中我想使用 $set 操作或 findAndModify 之类的 Query。考虑到上面的课程,我想找到具有给定用户名集的所有记录,并想通过某个值“abc”更新所有记录的 applicationId。

是否有任何约定可以实现这两种情况?