我有一个问题,我以前没有看到Mongoose findByIdAndUpdate没有在回调中返回正确的模型.
这是代码:
var id = args._id;
var updateObj = {updatedDate: Date.now()};
_.extend(updateObj, args);
Model.findByIdAndUpdate(id, updateObj, function(err, model) {
if (err) {
logger.error(modelString +':edit' + modelString +' - ' + err.message);
self.emit('item:failure', 'Failed to edit ' + modelString);
return;
}
self.emit('item:success', model);
});
Run Code Online (Sandbox Code Playgroud)
db中的原始文档如下所示:
{
_id: 1234
descriptors: Array[2],
name: 'Test Name 1'
}
Run Code Online (Sandbox Code Playgroud)
updateObj进入如下:
{
_id: 1234
descriptors: Array[2],
name: 'Test Name 2'
}
Run Code Online (Sandbox Code Playgroud)
从回调返回的模型与原始模型相同,而不是updatedObj.如果我查询数据库,它已被正确更新.它只是没有从数据库返回.
这感觉就像一个'愚蠢的用户'错误,但我看不到它.任何想法都非常感激.
我很难失败,无法将单个集合恢复到现有数据库中.我正在使用mongo 2.6.7版运行Ubuntu 14.04.根据我的主目录有一个dump/mydbname/contents.bson.
如果我跑
mongorestore --collection contents --db mydbname
Run Code Online (Sandbox Code Playgroud)
然后我得到:
connected to: 127.0.0.1
don't know what to do with file [dump]
Run Code Online (Sandbox Code Playgroud)
如果我添加路径
mongorestore --collection contents --db mydbname --dbpath dump/mydbname
Run Code Online (Sandbox Code Playgroud)
然后我明白了
If you are running a mongod on the same path you should connect to that instead of direct data file access
Run Code Online (Sandbox Code Playgroud)
我已经尝试了各种其他组合,选项等等,并且无法解决它,所以我来到社区寻求帮助!
我遇到了一个大问题,试图通过模块将一些常见的模式定义共享给我的代码库中的所有其他模块.
我有一个包含这两个模式的myproj_schemas模块:
var mongoose = require('mongoose'),
util = require("util"),
Schema = mongoose.Schema;
var BaseProfileSchema = function() {
Schema.apply(this, arguments);
this.add({
_user: {type: Schema.Types.ObjectId, ref: 'User', required: true},
name: {type: String, required: true},
bio: {type: String, required: true},
pictureLink: String
});
};
util.inherits(BaseProfileSchema, Schema);
module.exports = BaseProfileSchema;
Run Code Online (Sandbox Code Playgroud)
和
var mongoose = require('mongoose'),
BaseProfileSchema = require('./base_profile_schema.js'),
Schema = mongoose.Schema;
var entSchemaAdditions = {
mentors: {type: Schema.Types.ObjectId, ref: 'Mentor'}
};
var entrepreneurSchema = new BaseProfileSchema(entSchemaAdditions);
module.exports = entrepreneurSchema;
Run Code Online (Sandbox Code Playgroud)
导师也在另一个文件中定义.
我的单元测试都在模式模块中工作.
当我npm安装此模块并尝试创建使用
Entrepreneur = …Run Code Online (Sandbox Code Playgroud) I have a table of data that looks a bit like this:
Name StartTime FinishTime Work
Bob 2010-08-03 08:00:00 2010-08-03 12:00:00 4
Bob 2010-08-03 13:00:00 2010-08-03 16:00:00 3
Pete 2010-08-04 08:00:00 2010-08-04 12:00:00 4
Mark 2010-08-04 10:00:00 2010-08-04 12:00:00 2
Run Code Online (Sandbox Code Playgroud)
None of these date ranges should ever span over midnight.
I want to write SQL that will give me the following output, given an input Start Date of 2010-08-02 and a Finish Date of 2010-08-05
Date Name TotalWork
2010-08-03 Bob …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用数据类型"对话框"来获取一个div,以便在JQuery Mobile中显示,由Javascript事件触发.下面示例中的按钮单击纯粹是为了触发事件.
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//$.mobile.changePage('#addCatForm');
$('#createEvent').click (function () {
console.log('Prove event fired');
$.mobile.changePage('#addCatForm', {
transition: 'pop',
changeHash: false,
role: 'dialog'
});
});
});
</script>
</head>
<body>
<div data-role="page" id="mainPage">
<button id="createEvent">Create Event</button>
<div data-role="dialog" id="addCatForm" data-theme="c">
<p>here is some text</p>
<div data-role="content">
<input type="text" id="catText" data-theme="c"/>
<input data-role="button" data-mini="true" data-theme="b" data-inline="true" type="submit" id="addCat" value="Add Category">
<button data-role="button" data-mini="true" data-theme="c" data-inline="true" id="canCat">Cancel</button>
</div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
console.log输出正确触发,但我无能为力似乎要显示对话框.
任何帮助赞赏.
谢谢,
我是Mongoose/Mongo和node.js的新手,所以我怀疑这只是我身边的一个误解,但......
下面的代码示例是最小的失败示例,而不是我的用例.
var User = app.db.model('User');
User.find({email: 'm8@test.com'}, function (err, models) {
models[0].update(function(err, mod) {
console.log(err.message)
});
});
Run Code Online (Sandbox Code Playgroud)
这会导致以下错误:将更新应用于文档{_id:ObjectId('54647402cb955748153ea782'),...}后,发现(不可变)字段'_id'已更改为_id:ObjectId('546d9e0e539ed9ec102348f9 ")
为什么会这样?我原本以为从初始查找返回的模型上调用update会没问题.
请注意:在我的用例中,查找和更新之间发生了一些事情.具体来说,我正在做类似的事情:
model.property.push(objectId)
Run Code Online (Sandbox Code Playgroud)
然后我想通过更新提交.
我确信这是一个直截了当的问题,但我无法在文档的任何地方看到我可能会弄错它.
所有帮助赞赏.
我实际需要做的是:
var User = app.db.model('User');
User.find({email: 'm8@test.com'}, function (err, models) {
models[0].save(function(err, mod) {
console.log(err.message)
});
});
Run Code Online (Sandbox Code Playgroud)
使用"保存"而不是"更新"
无论如何,我正在尝试从浏览器上传文件,然后将其读入服务器上的XmlDocument对象.最初我通过将文件保存到磁盘,将其读入XmlDocument对象然后删除文件来解决此问题.唯一的问题是删除操作是在XmlDocument.Load操作完成之前尝试进行的.无论如何,这感觉就像一个丑陋的解决方案,所以它被高兴地抛弃了.
接下来的努力是直接从Request.Files[x].InputStream直接读入XmlDocument,但我遇到了问题.以下代码失败,带有
'根元素缺失'
我知道XML是有效的,所以它必须是别的东西.
foreach (string file in Request.Files)
{
HttpPostedFileBase postedFile = Request.Files[file] as HttpPostedFileBase;
if (postedFile.ContentLength > 0) //if file not empty
{
//create an XML object and load it in
XmlDocument xmlProjPlan = new XmlDocument();
Stream fileStream = postedFile.InputStream;
byte[] byXML = new byte[postedFile.ContentLength];
fileStream.Read(byXML, 0, postedFile.ContentLength);
xmlProjPlan.Load(fileStream);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经和很多网络应用程序项目合作了几个星期了.这些是使用LINQ to SQL的C#MVC Web应用程序.
在我开放Visual Studio的最后几天,它一直在向我展示以下对话.
web.config文件中的connection属性缺失或不正确.来自.dbml文件的连接字符串已在其位置使用.
我不知道为什么我得到这个.我没有更改Web.Config或数据库中的任何内容.它影响了所有项目,甚至是我几周没开的项目.
我在网上看到的唯一一件事就是:http: //www.stuffthatjustworks.com/How+To+Fix+LINQ+To+SQL+DBML+Issue+The+Connection+Property+Of+The+Webconfig +文件是+缺少+或者+ Incorrect.aspx
但是,感觉就像一个完整的VS卸载和注册表黑客有点极端.
以前有人碰到过这个,知道它为什么会发生并知道如何解决它吗?
谢谢,
作为一个正则表达式的新手,这让我感到沮丧 - 所有的帮助表示赞赏.我有这样的事情:
<img src="https://jdfsdf.dsfsdf.sdfsd/upload/sm/dsfsdf/sdfsdf/sdfdsf.jpg" style="..." id="..">
Run Code Online (Sandbox Code Playgroud)
我希望它是:
<img src="https://jdfsdf.dsfsdf.sdfsd/upload/lg/dsfsdf/sdfsdf/sdfdsf.jpg" style="..." id="..">
Run Code Online (Sandbox Code Playgroud)
基本上,改变/ sm/to/lg /.我想通过PHP中的RegEx来做这件事,我正在使用http://www.phpliveregex.com/进行测试.
我可以简单地做到这一点,但是使用一个简单的PHP str_replace具有较低的健壮性 - 为了这个问题,我想用RegEx保留答案.
我试过使用后视,如下所示:
(?<=<img src.+upload\/)sm
Run Code Online (Sandbox Code Playgroud)
这显然不起作用,但下面的代码确实符合所需的要点.
<img src.+upload\/
Run Code Online (Sandbox Code Playgroud)
我很难过.任何帮助或链接到一个体面的教程,涵盖这一点将不胜感激.
mongodb ×4
mongoose ×3
node.js ×3
asp.net ×1
asp.net-mvc ×1
c# ×1
html ×1
javascript ×1
jquery ×1
php ×1
regex ×1
sql ×1
t-sql ×1
ubuntu-14.04 ×1