Mongoid删除嵌入式文档不会持续(Mongoid deleting embedded documents does not persist)
我几个小时就遇到了一个问题,并且Google自己没有任何意义。
我有一个嵌入式文档的Mongoid模型,如下所示:
embeds_many :tags, :as => :taggable
出于某种原因,尝试删除此文档似乎在控制台中工作,但在重新加载之后文档会返回。 我已经尝试了以下内容:
model.tags.delete_all model.tags.each do |tag| tag.delete end model.tags.destroy_all
完成上述所有操作后,我可以确认model.tags返回一个空数组。 然后为了安全起见,我甚至打电话给model.save。 如果我重新加载模型,所有嵌入的标签都会返回。
使用Mongoid删除嵌入文档的正确方法是什么?
I have been running into an issue for hours and have Googled myself senseless.
I have a Mongoid model with an embedded document, like so:
embeds_many :tags, :as => :taggable
For some reason, attempting to delete this document appears to work in the console but then the documents come back after a reload. I have tried the following:
model.tags.delete_all model.tags.each do |tag| tag.delete end model.tags.destroy_all
After all of the above, I can confirm that model.tags returns an empty array. Then to be safe, I even call model.save. If I reload the model, all of the embedded tags come back.
What is the correct way to delete embedded documents using Mongoid?
原文:https://stackoverflow.com/questions/9972089
最满意答案
Unix crontab有5个字段 ; 分钟,小时,月,月,星期几。
这一行:
every '* * * * * *' do 1 2 3 4 5 6 <- Error
你输入的字段太多了。
The Unix crontab has 5 fields; minute, hour, day of month, month, day of week.
This line:
every '* * * * * *' do 1 2 3 4 5 6 <- Error
You entered too many fields.
相关问答
更多-
Unix crontab有5个字段 ; 分钟,小时,月,月,星期几。 这一行: every '* * * * * *' do 1 2 3 4 5 6 <- Error 你输入的字段太多了。 The Unix crontab has 5 fields; minute, hour, day of month, month, day of week. This line: every '* * * * * *' do 1 2 3 4 5 6 <- Error You entered ...
-
如CentOS中的安装crontab所示,CentOS中的crontab软件包是vixie-cron 。 因此,请安装它: yum install vixie-cron 然后开始: service crond start 要使其持久化,以便在引导时启动,请使用: chkconfig crond on 在CentOS 7上,您需要使用cronie : yum install cronie 在CentOS 6上,您可以安装vixie-cron ,但真正的包是cronie : yum install vi ...
-
Shell Crontab无法正常工作(Shell Crontab not working)[2023-06-09]
首先确保您的脚本是可执行的: chmod u+x name_of_script 现在将其添加到crontab: crontab -e 还要确保您在crontab中编写完整路径,例如: */5 * * * * /home/user/loadcheck.sh First make sure your scripts are executable: chmod u+x name_of_script Now add it to crontab: crontab -e Also make sure you ... -
没有任何选项的命令crontab从stdin安装crontab。 如果需要附加到旧的crontab, crontab -l将返回当前的crontab。 The command crontab without any options installs a crontab from stdin. crontab -l returns the current crontab if you need to append to the old crontab.
-
Crontab没有运行(Crontab not running)[2022-05-27]
你缺少环境变量。 尝试这样的简单测试 将此添加到您的crontab * * * * * set > /tmp/vars 等待2-3分钟,返回并删除刚刚创建的crontab条目。 下一个, 从通常使用的shell命令行 set > myvars diff myvars /tmp/vars 这将向您展示环境的不同之处。 修改您的cron作业环境。 只需添加所需内容即可。 You are missing envrionment variables. Try a simple test like this a ... -
我终于能够通过两个步骤来解决这个问题了: 首先从virt-install命令中删除'console'相关配置。 在上面的命令中看到额外的参数。 把一些逻辑等待virt-install完成。 我在kickstart文件的安装后部分添加了shutdown,以便在完成所有软件包的安装后关闭VM。 然后在我的脚本中,我实际上“等待”VM进入关闭状态,然后再转到下一个命令。 这样我就可以在crontab中运行我的脚本。 它也与詹金斯一起工作。 希望这可以帮助面临同样问题的人。 I finally able to ca ...
-
保存Crontab文件(Saving Crontab files)[2024-04-23]
通常情况下,您使用crontab创建文件,并将其存储在机器的正确位置。 $ crontab < $HOME/etc/crontab 然后你使用crontab -l来列出它。 $ crontab -l # @(#)$Id: crontab,v 4.2 2007/09/17 02:41:00 jleffler Exp $ # Crontab file for Home Directory for Jonathan Leffler (JL) #------------------------------ ... -
根据crontab.guru , * * * * *和*\1 * * * *基本上是相同的,尽管您可能想尝试替代方案,以防万一您的系统不喜欢其中一个或另一个。 但是,在您发布的home.cron ,路径是错误的。 这个: * * * * * /users/username/desktop/forTrump/script.sh 应该: * * * * * /Users/username/Desktop/forTrump/script.sh 但是,如果脚本需要提升的权限,那么您将需要使用root cron ...
-
CRONTAB出了点问题(Something is wrong with CRONTAB)[2022-04-07]
正如在评论中通知的那样,问题是我使用了相对路径而不是绝对路径 As notified in a comment, problem was that I used relative path instead of an absolute path -
正如你在Python中想要的那样,你可以做这样的“事情”: import os; ... cur_cron = os.popen('crontab -l > current_crontab.txt'); cur_cron.read(); cur_cron.close(); fopen_cron = file('current_crontab.txt', 'a'); fopen_cron.write("\n### Comment here if you like"); fopen_cron.write("\n ...