首先,我正在对mongoDB进行查询,得到所有正确的结果,但只对对象文字的小修改不起作用.我想做的是为评论添加新字段.我尝试使用DBref方法,但它没有工作,所以我现在进行2次查询.
var query = Rss.findOne({ _id: itemId});
query.exec(function(err, feed) {
if (!err && feed.comments) {
console.log(feed.comments.length);
for (var index in feed.comments) {
var author = feed.comments[index].author;
if (author !== undefined) {
User.findById(author, function(err, user) {
/**Problem is here **/
feed.comments[index].name = 'Some random field';
console.log('Added new field' + util.inspect(feed));
});
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
响应是没有缺少.name字段的响应.
Added new field{ _id: 4f34f343c7b0434217000012,
original_link: 'http://com',
publish_date: Fri, 10 Feb 2012 10:36:00 GMT,
summary: 'some text',
title: 'title exampel',
comments:
[ …Run Code Online (Sandbox Code Playgroud) 你使用什么缓存策略?我阅读了脱机食谱,最简单的策略是缓存静态内容,遗漏API调用.
这个策略看起来像这样:
如果在服务器端文件已更改,如何更新缓存?目前,客户端始终获得缓存结果.
这是我的缓存策略的代码:
// You will need this polyfill, at least on Chrome 41 and older.
importScripts("serviceworker-cache-polyfill.js");
var VERSION = 1;
var CACHES = {
common: "common-cache" + VERSION
};
// an array of file locations we want to cache
var filesToCache = [
"font-cache.html",
"script.js",
];
var neededFiles = [
"index.html"
];
var errorResponse = function() {
return new Response([
"<h2>Failed to get file</h2>",
"<p>Could not retrive response from cache</p>"
].join("\n"),
500
);
}; …Run Code Online (Sandbox Code Playgroud)是否可以使用Cloudformation模板创建SNS平台应用程序?
支持aws-cli,http://docs.aws.amazon.com/cli/latest/reference/sns/create-platform-application.html。但是没有关于使用Cloudformation进行相同操作的信息,它是否完全受支持(http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html)?
我在使用nodejs request流时遇到问题,因为我传递给它已经是空的数组.
var _ = require('highland'),
fs = require('fs'),
request = require('request');
// This works but not using the stream approach
// function get(path) {
// return _(function (push, next) {
// request(path, function (error, response, body) {
// // The response itself also contains the body
// push(error, response);
// push(null, _.nil);
// });
// });
// }
var google = _(request.get('http://www.google.com'));
google
// res is empty array
.map(function (res) {
// console.log(res);
return res;
})
// res …Run Code Online (Sandbox Code Playgroud)