小编Ion*_*zău的帖子

获取MongoDB中的更新文档

我需要获取_id更新文档的(Mongo ObjectID).为此我想获得更新的文件.我怎么才能得到它?

我试过这个:

...
collection.update(oldData, newData, function(err, doc) {
    console.log(docs); // This prints "1" in console. So, it's not a document.
    if (err) { return callback(err); }
    callback(null, doc);
});
...
Run Code Online (Sandbox Code Playgroud)

我可以在没有通过newData/oldData查找文档的情况下获取它吗?

javascript mongodb node.js

5
推荐指数
1
解决办法
2971
查看次数

前景中的本地通知

在警报中,通知在后台工作正常如下:

    UILocalNotification *notification1=[[UILocalNotification alloc]init];
    notification1.fireDate=alramtime;
    notification1.alertBody=@"Training Time";
    notification1.repeatInterval=NSDayCalendarUnit;

    notification1.soundName=@"Alarm.caf";

    ///////
    previousnotif=[[NSUserDefaults standardUserDefaults]objectForKey:@"notif1"];
    previous=[NSKeyedUnarchiver unarchiveObjectWithData:previousnotif];

    NSLog(@"alarm %@",previous);
    if (previous!= NULL) {
        [[UIApplication sharedApplication]cancelLocalNotification:previous];
        [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"notif1"];

    }
    NSData *alarm1=[NSKeyedArchiver archivedDataWithRootObject:notification1];
    [notifdefaults setObject:alarm1 forKey:@"notif1"];
    /////////


    [[UIApplication sharedApplication] scheduleLocalNotification:notification1];
    NSLog(@"new alarm %@",notification1);
Run Code Online (Sandbox Code Playgroud)

但是当我修改它以便在前景中播放时如下:..它不工作..只有警报出现但没有声音???

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {


   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"KNIP"
                                                   message:notification.alertBody
                                                   delegate:self cancelButtonTitle:@"Close"
                                          otherButtonTitles:nil];  

[alert show];

}
@end
Run Code Online (Sandbox Code Playgroud)

当我记录声音文件等通知属性时......它们工作得很好......但是没有声音......

notifications local objective-c ios

5
推荐指数
2
解决办法
6979
查看次数

在C#中使用计时器实现循环

我想在C#中使用基于定时器的while循环替换基于while循环的计数器.

示例:

while(count < 100000)
{
   //do something 
}
Run Code Online (Sandbox Code Playgroud)

while(timer < X seconds)
{
    //do something 
}
Run Code Online (Sandbox Code Playgroud)

我有两种类型的C#.NET定时器本的System.TimersThreading.Timers.哪一个会更好用,怎么样.我不想在计时器上增加额外的时间消耗或线程问题.

c# loops timer countdowntimer

5
推荐指数
3
解决办法
5万
查看次数

MongoDB回调不会抛出引用错误

介绍

所有人都知道,如果我们打电话,undefined.test我们将收到以下错误(两者都相同:NodeJS和Javascript):

$ node
> undefined.test
TypeError: Cannot read property 'test' of undefined
    at repl:1:11
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)
    at emitKey (readline.js:1095:12)
Run Code Online (Sandbox Code Playgroud)

那是对的!

我是怎么发现这个问题的?

通过一周我在调试以下问题时浪费了大约30分钟:脚本意外停止并且没有抛出任何错误.

我有一个urls应该是一个对象的变量:

var urls = settings.urls || {}; 
Run Code Online (Sandbox Code Playgroud)

然后在接下来的行中,我需要获取shop密钥,urls这是一个字符串:

var shop = urls.shop || "/";
Run Code Online (Sandbox Code Playgroud)

我开始添加console.log以查找变量的值:

console.log(urls);            // undefined
var shop = urls.shop || "/";
console.log("Passed"); …
Run Code Online (Sandbox Code Playgroud)

javascript mongodb node.js

5
推荐指数
1
解决办法
1061
查看次数

是否可以在命令行中列出git存储库问题?

在修复问题时,我想确保在提交消息中关闭正确的问题:"Fixed #issueId".

为了更快,我想列出终端中的存储库问题.这可能是git命令吗?

我想象下面的东西:

$ git issues --all

+---------------------------------------+
| Repository Name - Issues              |
+---------------------------------------+
| # | Title                   | Status  |
+---------------------------------------+
| 1 | Lorem Ipsum 1           | OPEN    |
| 2 | Lorem Ipsum 2           | WONTFIX |
| 3 | Lorem Ipsum 3           | RESOLVED|
| 4 | Lorem Ipsum 4           | INVLID  |
+---------------------------------------+
Run Code Online (Sandbox Code Playgroud)

git github bitbucket

5
推荐指数
1
解决办法
3827
查看次数

如何知道Mongoose的upsert是否创建了一个新文档?

我在node.js/express.js中有这个代码:

var User = mongoose.model('User');
var usersRouter = express.Router();
usersRouter.put('/:id', function(req, res) {
    req.body._id = req.params.id;
    var usr = new User(req.body);

    usr.validate(function (err) {
        if (err) {
            res.status(400).json({});
            return;
        }

        var upsertData = usr.toObject();
        delete upsertData._id;

        User.update({_id: usr._id}, upsertData, {upsert: true}, function(err) {
            if (err) {
                res.status(500).json({});
                return;
            }

            res.status(204).json({});
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我想在创建新文档时向客户端发送不同的响应(状态201,响应正文中为json)或现有的已更新(状态204).

有没有办法告诉回调的区别User.update

javascript mongoose mongodb node.js express

5
推荐指数
1
解决办法
1054
查看次数

更改以模式开头的提交的提交作者(在消息中)

我有一个存储库,其中有一些(实际上很多)提交由程序生成,如下所示:

Adding new domains: example.com
Run Code Online (Sandbox Code Playgroud)

它发生了(因为配置错误)这些提交是以同事的名义进行的.现在,我想更改这些提交作者:

Some Bot <bot@example.com>
Run Code Online (Sandbox Code Playgroud)

Github在此处发布一个公共脚本,用于更改由旧作者过滤的提交.在这种情况下,我想更改提交的作者,其中消息以模式开头:添加新域:.我怎样才能做到这一点?

git

5
推荐指数
2
解决办法
215
查看次数

GA嵌入API - 选择每小时,每天,每周或每月

我使用GA嵌入API(https://developers.google.com/analytics/devguides/reporting/embed/v1/)在我的网站上添加了一些图表.我可以为每个报告选择日期范围(开始日期和结束日期).

我在报告图表中想要这些"每小时","日","周","月".我认为必须有一个按时间单位对数据进行分组的参数,但我找不到它.如何在图表中添加选择时间单位的选项?

例

javascript google-analytics google-analytics-api google-reporting-api

5
推荐指数
1
解决办法
696
查看次数

受支持的git url格式是什么?

Git接受许多不同的URL格式(例如ssh,http,https等)。有什么规格/官方文档可以找到受支持的git url格式吗?

我写了一个git url解析器,我想确保在那里做的是正确的。

在这里,在YonderGit上,我找到了以下列表。由于https://<token>:x-oauth-basic@host.xz/path/to/repo.git不存在,因此不完整。

安全外壳传输协议

  • ssh://user@host.xz:port/path/to/repo.git/
  • ssh://user@host.xz/path/to/repo.git/
  • ssh://host.xz:port/path/to/repo.git/
  • ssh://host.xz/path/to/repo.git/
  • ssh://user@host.xz/path/to/repo.git/
  • ssh://host.xz/path/to/repo.git/
  • ssh://user@host.xz/~user/path/to/repo.git/
  • ssh://host.xz/~user/path/to/repo.git/
  • ssh://user@host.xz/~/path/to/repo.git
  • ssh://host.xz/~/path/to/repo.git
  • user@host.xz:/path/to/repo.git/
  • host.xz:/path/to/repo.git/
  • user@host.xz:~user/path/to/repo.git/
  • host.xz:~user/path/to/repo.git/
  • user@host.xz:path/to/repo.git
  • host.xz:path/to/repo.git
  • rsync://host.xz/path/to/repo.git/

Git传输协议

  • git://host.xz/path/to/repo.git/
  • git://host.xz/~user/path/to/repo.git/

HTTP / S传输协议

  • http://host.xz/path/to/repo.git/
  • https://host.xz/path/to/repo.git/

本地(文件系统)传输协议

  • /path/to/repo.git/
  • path/to/repo.git/
  • ~/path/to/repo.git
  • file:///path/to/repo.git/
  • file://~/path/to/repo.git/

git ssh github

5
推荐指数
1
解决办法
5046
查看次数

获取特定作者的提交(不止一个)

如果我想得到Alice提交,我会使用git log --author 'Alice'.但是,如果我想包括那些Bob提交怎么办?

我尝试了以下方法:

git log --author 'Alice|Bob'
git log --author 'Alice,Bob'
Run Code Online (Sandbox Code Playgroud)

git commit

5
推荐指数
1
解决办法
38
查看次数