MongoDB natural sort returns data with ObjectIDs shuffled in time - mongodb

I perform the following query:
db.preference.find({}, {_id: 1}).sort({$natural: 1}).forEach(function(d) {
print(d._id.getTimestamp())
})
Here's part of the output:
Thu Mar 26 2015 12:39:06 GMT+0100 (CEST)
Thu Mar 26 2015 12:41:07 GMT+0100 (CEST)
Thu Mar 26 2015 12:48:55 GMT+0100 (CEST)
Mon Mar 30 2015 17:08:44 GMT+0200 (CEST)
Tue Mar 31 2015 12:34:36 GMT+0200 (CEST)
Tue Mar 31 2015 12:35:01 GMT+0200 (CEST)
Tue Mar 31 2015 12:34:47 GMT+0200 (CEST)
Thu Nov 20 2014 10:55:07 GMT+0100 (CEST)
Wed Apr 29 2015 10:02:33 GMT+0200 (CEST)
Wed Apr 29 2015 10:02:53 GMT+0200 (CEST)
Wed Apr 29 2015 10:03:13 GMT+0200 (CEST)
Wed Apr 29 2015 10:00:11 GMT+0200 (CEST)
Wed Apr 29 2015 10:18:23 GMT+0200 (CEST)
Mon Feb 23 2015 11:54:11 GMT+0100 (CEST)
Tue May 12 2015 16:40:45 GMT+0200 (CEST)
Fri May 15 2015 17:04:04 GMT+0200 (CEST)
Wed May 14 2014 18:13:40 GMT+0200 (CEST)
Tue Jun 09 2015 14:17:11 GMT+0200 (CEST)
Tue Jun 16 2015 16:03:31 GMT+0200 (CEST)
Tue Nov 04 2014 21:15:21 GMT+0100 (CEST)
Fri Mar 14 2014 10:16:48 GMT+0100 (CEST)
Wed Jun 17 2015 11:14:57 GMT+0200 (CEST)
Fri Mar 14 2014 10:15:30 GMT+0100 (CEST)
It's easy to see that the dates are seriously shuffled, while I expected strictly ascending order.
Collection is not capped, and the documents are often modified. ObjectIds are never generated in the code explicitly. Collection is not shared.
Any ideas why natural sorting works this way?
Can someone explain while natural ordering works in.

What did you expect?
Use the $natural operator to use natural order for the results of a
sort operation. Natural order refers to the logical ordering of
documents internally within the database.
The $natural operator uses the following syntax to return documents in
the order they exist on disk: ...
See MongoDB documentation.

Related

IPython /bin/bash: /bin/bashfile.txt: Permission denied

This issue is inside IPython:
1) when i run the following, it works fine
for x in range(10):
!date
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
Tue Jun 12 13:25:18 EDT 2018
2) when i want to redirect it into the file, it gives the following error message:
for x in range(10):
!date > ${x}.txt
/bin/bash: /bin/bashfile.txt: Permission denied
Im honestly not sure why am i getting that error message. I don't understand it.
If you want to interpolate the value of the Python variable x into a shell command in IPython, the syntax for that is $x or {x}, not ${x}. When x is 0, ${x} expands to $0, which the shell then does its own expansion for. Your command should be
!date > {x}.txt
(It's unlikely that $0 would have expanded to /bin/bashfile, suggesting that you probably didn't actually run the code you posted.)
Not sure what exactly you are trying to do here, but you're trying to write to a file that you do not have write permission for.
Make a new file and try writing to it and you'll succeed.

Why are jobs queued twice by beanstalkd after 2 minutes

I have the following environment and I notice that the jobs are queued twice randomly after 2 minutes:
Web App based on PHP F3 framework
Pheanstalk 3.0.2 using composer in the app
Beanstalkd server
Beanstalkd console app
Supervisord
Worker scenario: entering multiple jobs to bulk delete clients
Issue: same job (already processed) is queued twice after 2 minutes with different ID
I use the following code:
$queue = new Pheanstalk\Pheanstalk("127.0.0.1:14803");
$queue->watch("tubeDelete");
while ($job = $queue->reserve()) {
$log->write("Entering Job {$job->getId()} \n");
$log->write("Job {$job->getId()} data : {$job->getData()} \n");
$data = json_decode($job->getData(), true);
try {
$deleteResponse = $client->deleteClient($clientId)
if($deleteResponse){
$log->write("client $clientId deleted successfully");
$queue->delete($job);
}else{
$log->write("Failed to delete client $clientId, check the log file");
$queue->bury($job);
}
} catch (Exception $e) {
$log->write("Failed to delete client $clientId with PHP exception, check the log file");
$queue->bury($job);
}
}
Log file:
Fri, 08 Dec 2017 13:00:23 +0200 Entering Job 92428501
Fri, 08 Dec 2017 13:00:23 +0200 Job 92428501 data : {"clientId":"1397"}
Fri, 08 Dec 2017 13:00:24 +0200 Client 1397 deleted successfully
Fri, 08 Dec 2017 13:00:24 +0200 Entering Job 92428502
Fri, 08 Dec 2017 13:00:24 +0200 Job 92428502 data : {"clientId":"1398"}
Fri, 08 Dec 2017 13:00:26 +0200 Client 1398 deleted successfully
Fri, 08 Dec 2017 13:00:26 +0200 Entering Job 92428503
Fri, 08 Dec 2017 13:00:26 +0200 Job 92428503 data : {"clientId":"1399"}
Fri, 08 Dec 2017 13:00:28 +0200 Client 1399 deleted successfully
Fri, 08 Dec 2017 13:00:28 +0200 Entering Job 92428504
Fri, 08 Dec 2017 13:00:28 +0200 Job 92428504 data : {"clientId":"1401"}
Fri, 08 Dec 2017 13:00:30 +0200 Client 1401 deleted successfully
Fri, 08 Dec 2017 13:00:30 +0200 Entering Job 92428505
Fri, 08 Dec 2017 13:00:30 +0200 Job 92428505 data : {"clientId":"1402"}
Fri, 08 Dec 2017 13:00:31 +0200 Client 1402 deleted successfully
Fri, 08 Dec 2017 13:00:31 +0200 Entering Job 92428506
Fri, 08 Dec 2017 13:00:31 +0200 Job 92428506 data : {"clientId":"1403"}
Fri, 08 Dec 2017 13:00:33 +0200 Client 1403 deleted successfully
Fri, 08 Dec 2017 13:00:33 +0200 Entering Job 92428507
Fri, 08 Dec 2017 13:00:33 +0200 Job 92428507 data : {"clientId":"1404"}
Fri, 08 Dec 2017 13:00:34 +0200 Client 1404 deleted successfully
Fri, 08 Dec 2017 13:00:34 +0200 Entering Job 92428508
Fri, 08 Dec 2017 13:00:34 +0200 Job 92428508 data : {"clientId":"1405"}
Fri, 08 Dec 2017 13:00:36 +0200 Client 1405 deleted successfully
Fri, 08 Dec 2017 13:00:36 +0200 Entering Job 92428509
Fri, 08 Dec 2017 13:00:36 +0200 Job 92428509 data : {"clientId":"1409"}
Fri, 08 Dec 2017 13:00:37 +0200 Client 1409 deleted successfully
Fri, 08 Dec 2017 13:00:37 +0200 Entering Job 92428510
Fri, 08 Dec 2017 13:00:37 +0200 Job 92428510 data : {"clientId":"1421"}
Fri, 08 Dec 2017 13:00:38 +0200 Client 1421 deleted successfully
Fri, 08 Dec 2017 13:02:23 +0200 Entering Job 92428511
Fri, 08 Dec 2017 13:02:23 +0200 Job 92428511 data : {"clientId":"1397"}
Fri, 08 Dec 2017 13:02:23 +0200 Client 1397 deleted successfully
Fri, 08 Dec 2017 13:02:23 +0200 Entering Job 92428512
Fri, 08 Dec 2017 13:02:23 +0200 Job 92428512 data : {"clientId":"1398"}
Fri, 08 Dec 2017 13:02:23 +0200 Client 1398 deleted successfully
Fri, 08 Dec 2017 13:02:23 +0200 Entering Job 92428513
Fri, 08 Dec 2017 13:02:23 +0200 Job 92428513 data : {"clientId":"1399"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1399 deleted successfully
Fri, 08 Dec 2017 13:02:24 +0200 Entering Job 92428514
Fri, 08 Dec 2017 13:02:24 +0200 Job 92428514 data : {"clientId":"1401"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1401 deleted successfully
Fri, 08 Dec 2017 13:02:24 +0200 Entering Job 92428515
Fri, 08 Dec 2017 13:02:24 +0200 Job 92428515 data : {"clientId":"1402"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1402 deleted successfully
Fri, 08 Dec 2017 13:02:24 +0200 Entering Job 92428516
Fri, 08 Dec 2017 13:02:24 +0200 Job 92428516 data : {"clientId":"1403"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1403 deleted successfully
Fri, 08 Dec 2017 13:02:24 +0200 Entering Job 92428517
Fri, 08 Dec 2017 13:02:24 +0200 Job 92428517 data : {"clientId":"1404"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1404 deleted successfully
Fri, 08 Dec 2017 13:02:24 +0200 Entering Job 92428518
Fri, 08 Dec 2017 13:02:24 +0200 Job 92428518 data : {"clientId":"1405"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1405 deleted successfully
Fri, 08 Dec 2017 13:02:24 +0200 Entering Job 92428519
Fri, 08 Dec 2017 13:02:24 +0200 Job 92428519 data : {"clientId":"1409"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1409 deleted successfully
Fri, 08 Dec 2017 13:02:24 +0200 Entering Job 92428520
Fri, 08 Dec 2017 13:02:24 +0200 Job 92428520 data : {"clientId":"1421"}
Fri, 08 Dec 2017 13:02:24 +0200 Client 1421 deleted successfully
So, you can find the repeated clients due to executing the same job after 2 minutes, for example:
Fri, 08 Dec 2017 13:00:23 +0200 Entering Job 92428501
Fri, 08 Dec 2017 13:00:23 +0200 Job 92428501 data : {"clientId":"1397"}
Fri, 08 Dec 2017 13:00:24 +0200 Client 1397 deleted successfully
Fri, 08 Dec 2017 13:02:23 +0200 Entering Job 92428511
Fri, 08 Dec 2017 13:02:23 +0200 Job 92428511 data : {"clientId":"1397"}
Fri, 08 Dec 2017 13:02:23 +0200 Client 1397 deleted successfully
Is it the issue related to TTR / DEADLINE_SOON / configuration issue or related to supervisord?

How to debug a splice operation in a Perl script?

#! usr/bin/perl
#months=('Jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
#new=('1','2');
print "#months\n";
splice(#months,0,1,#new);
print "#months\n";
When I run this I expect output to be as
Jan feb mar apr may jun jul aug sep oct nov dec
1 2 mar apr may jun jul aug sep oct nov dec
But I am getting output as
Jan feb mar apr may jun jul aug sep oct nov dec
1 2 feb mar apr may jun jul aug sep oct nov dec
The Feb should also be replaced by 2, right? But why it isn't happening.
Syntax of splice command is
splice ARRAY,OFFSET,LENGTH,LIST
You specify LENGTH to be 1, so only one element is removed from the original list (that element is Jan). If you want feb to be removed too, then you must use a LENGTH of 2
splice(#months, 0, 2, #new);

Looking for Google Apps script to find and highlight dates from past month in red

I have a Google spreadsheet with columns I and J with data as headers Est Closing Month and Est Closing Calendar Year respectively, I need a script which will loop through columns I and J and find dates which are in the past month of this year and highlight them in Red.
Following is example data
ColI ColJ
Aug 2014
Nov 2014
Aug 2014
Jul 2014
Jul 2014
Dec 2014
Dec 2014
After I run the script the output put should be
Aug 2014
Nov 2014
Aug 2014
Jul 2014 -> Both Cells should be in red
Jul 2014 -> Both Cells should be in red
Dec 2014
Dec 2014
Thank you for all the help.
have you tried conditional formatting ?

How can I tell what version of eclipse I have?

I'm trying to use the eclipse delta pack, and I need to use the same exact version of the delta pack as the version of eclipse I'm using. When looking at Help>About Eclipse I see:
Version: 3.7.0.v20110530-9gF7UHNFFt4cwE-pkZDJ7oz-mj4OSEIlu9SEv0f
Build id: I20110613-1736
However, it seems the versions listed on the eclipse site have a different format. Here are the versions listed here: http://archive.eclipse.org/eclipse/downloads/
3.7RC4 Fri, 3 Jun 2011 -- 09:09 (-0400)
3.7RC3 Thu, 26 May 2011 -- 17:08 (-0400)
3.7RC2 Thu, 19 May 2011 -- 11:38 (-0400)
3.7RC1 Thu, 12 May 2011 -- 20:00 (-0400)
3.7M7 Thu, 28 Apr 2011 -- 08:48 (-0400)
3.7M6 Thu, 10 Mar 2011 -- 11:19 (-0500)
3.7M5 Thu, 27 Jan 2011 -- 20:34 (-0500)
3.7M4 Wed, 8 Dec 2010 -- 13:00 (-0500)
3.7M3 Thu, 28 Oct 2010 -- 14:41 (-0400)
3.7M2a Tue, 21 Sep 2010 -- 10:24 (-0400)
3.7M1 Thu, 5 Aug 2010 -- 17:00 (-0400)
Which version do I use?
Assuming you have the latest version.
I would say you can go for 3.7RC4 Fri, 3 Jun 2011 -- 09:09 (-0400) looking at the Build id: I20110613-1736 - 2011 Jun 13 #17:36
You have the latest 3.7 build.
I20110613-1736 corresponds to 3.7 Mon, 13 Jun 2011 -- 17:36 (-0400)
It is not in the list of archived downloads you posted.
If you want you can try the one which is closest to yours: 3.7RC4 Fri, 3 Jun 2011 -- 09:09 (-0400)