How do I get documents more recent than a particular document in Mongoid? - ruby

I am trying to do something like this in mongoid:
User.any_in(:uid => friends).and(:id.gt => "4d391ab448fa7d389b000000").entries
But looks like Mongoid ID cannot be compared this way. How do I achieve the above without resorting to using Mongoid::Timestamps ?
Thanks!

Why would you not want to use timestamps?
Using ids in this way will not give you the behavior you want.
The id of the document will depend not only on the order of insertion but also on what machine the id was generated on.
Timestamps are definitely your best bet here.

I guess you can use server side javascript to process the values but that would be less efficient and less secure if you care for these properties.

Related

How to massive delete in php-activerecord where id NOT in list?

I'm running a CodeIgniter application with PHP-Activerecord installed and I need to do a massive delete. The PHP-AR library supports massive update and delete, but the function only takes the ids that you want to delete/update. I'm trying to do a massive delete where the ids are NOT in the list.
delete from table where id not in (1,2,3...,500)
Unfortunately, the PHP-Activerecord website is of no help, and their forums are so horribly built (no search... seriously?) that I'm truly stuck.
edit: Please note, CodeIgniter's built-in ORM is not the same as PHP-Activerecord. Just thought I'd clarify that.
A bit late but this may help someone else. In PHPActiveRecord, do it in this way:
$ids_to_delete = array(1,2,3);
YourModel::delete_all(array('conditions' => array('id NOT IN (?)', $ids_to_delete)));
Ref: http://www.phpactiverecord.org/docs/ActiveRecord/Model#methoddelete_all
SInce active record is actually build string query with function, you can use this method:
- make your list as string
- make this query : $this->db->where('id not in',$string)->delete('table')

Using DiskVolumeInfo (Cluster Failover API)

I found the DiskVolumeInfo property -- I'd like to use it to get some disk information in a clustered setup.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb309235(v=vs.85).aspx
The problem is I have no idea what technology is required to get this data. This doesn't resemble the standard C/C++/C#/VB format of function/method reference.
Question: How do I get the DiskVolumeInfo data?
Ideally I could write the binary output directly to a file, say data.bin.
Any ideas would be helpful, thanks.
The process for getting object properties is described here.
Looks like you need to call the ClusterResourceControl function with a handle to the physical disk resource and the CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES control code. You can then use ResUtilFindBinaryProperty to extract the DiskVolumeInfo property from the property list returned.
For anyone still interested:
As given here CLUSCTL_RESOURCE_STORAGE_GET_DISK_INFO_EX is a better way to do this.

Twitter Ruby Gem - get friends names and ids, nothing more

Is it possible to simply get the people you are following with just an id and full name? I do not need any of the additional data, it's a waste of bandwidth.
Currently the only solution I have is:
twitter_client = Twitter::Client.new
friend_ids = twitter_client.friend_ids['ids']
friends = twitter_client.users(friend_ids).map { |f| {:twitter_id => f.id, :name => f.name} }
is there anyway to just have users returned be an array of ids and full names? better way of doing it than the way depicted above? preferably a way to not filter on the client side.
The users method uses the users/lookup API call. As you can see on the page, the only param available is include_entities. The only other method which helps you find users has the same limitation. So you cannot download only the needed attributes.
The only other thing I'd like to say is that you could directly use the friends variable, I don't see any benefit of running the map on it.

Adviced on how to array a mongodb document

I am building an API using Codeigniter and MongoDB.
I got some questions about how to "model" the mongoDB.
A user should have basic data like name and user should also be able to
follow other users. Like it is now each user document keeps track of all people
that is following him and all that he is following. This is done by using arrays
of user _ids.
Like this:
"following": [323424,2323123,2312312],
"followers": [355656,5656565,5656234234,23424243,234246456],
"fullname": "James Bond"
Is this a good way? Perhaps the user document should only contain ids of peoples that the user is following and not who is following him? I can imaging that keeping potentially thousands of ids (for followers) in an array will make the document to big?
All input is welcome!
The max-document size is currently limited to 16MB (v1.8.x and up), this is pretty big. But i still think, that it would be ok in this case to move the follower-relations to an own collection -- you never know how big your project gets.
However: i would recommend using database references for storing the follower-relations: it's way easier to resolve the user from a database reference. Have a look at:
http://www.mongodb.org/display/DOCS/Database+References

Duplicated Zend_Form Element ID in a page with various forms

How do I tell the Zend_Form that I want an element (and it's ID-label, etc) to use another ID value instead of the element's name?
I have several forms in a page. Some of them have repeated names. So as Zend_Form creates elements' IDs using names I end up with multiple elements with the same ID, which makes my (X)HTML document invalid.
What is the best solution to fix this, given that I really have to stick with using the same element names (they are a hash common to all forms and using the Zend_Form Hash Element is really out of question)?
Zend_Form_Element has a method called setAttribs that takes an array. You may be able to do something like $element->setAttribs(array('id' => "some_id"));
or you can do $element->setAttrib('id', 'some_id');
Thanks, Chris Gutierrez.
However, as I said, I needed to get ride of the default decorator generated IDs like -label. Wiht the $element->setAttribs() it is not possible, however.
So based on http://framework.zend.com/issues/browse/ZF-7125 I just did the following:
$element->clearDecorators();
$element->setAttrib('id', 'some_id');
$element->addDecorator("ViewHelper");
Whoever sees this: please note this was enough for what I needed. But may not be for you (the default settings has more than the viewHelper decorator).

Resources