What if phonenumber needs to be sorted by descending order, name needs to be sorted by ascending(lexicographical) order? - pyspark

What if phonenumber needs to be sorted by descending order, name needs to be sorted by ascending(lexicographical) order?
I expected how can realize it

Related

mongodb, sort documents ascending, with undefined bottom

I have documents collection where some documents have price, some don't.
I want to sort them ascending, with null(empty) last.
Googled some solutions:
Do two queries: first with price not null and price sorting, and second with price is null, and then combine data
Project new field with aggregate for sorting. Make it equal to price for documents with price and huge number where price is null. Then sort by this new field.
Is there any better/clean way to do it?

Order of results for `sort` using mongoose

If I have two equal values for a field. What would be the order of results for sort on that field? Random or ordered by insertion date?
If two documents have equal values for the field you're sorting on, then MongoDB will return the results in the order they are found on disk (ie Natural order)
from MongoDB Documentation :
natural order:
The order in which the database refers to documents on
disk. This is the default sort order. See $natural and Return in
Natural Order.
This may coincide with insertion date in some case, but not all of the time (especially when you perform insertion/deletion on your collection), so you should assume that this is random ordering

store documents in descending order(mongodb-insert)

I am trying to add and retrieve documents from collection.I went through mongodb manual and didn't find ways to add documents in descending order by date. Is it possible to add documents to collection in descending order by date while inserting the document as i don't want to query and return the top 50 documents.
TIA.
MongoDB does not guarantee the retrieval order of documents. Even if you insert them in descending order, there is no guarantee the records will be returned in this order. As suggested by BatScream you could add an descending index on your date field and the order your result when querying the data.

Sort Event in ZK

I have added comparators for sorting in asc,desc order.
listHeader.setSortAscending(new MyComparator(true)); //True for asc
listHeader.setSortDescending(new MyComparator(false)); //False for asc
when I do this. Events.postEvent(Events.ON_SORT,listHeader,null);
I get the listbox sorted in ascending order, but I want it to be sorted in descending order when I call above Events.postEvent(); am I missing setting any attribute?
Found answer :)
I had to set attribute Sort Direction to "ascending" listHeader.setSortDirection("ascending");

MongoDB: Count of matching nested array elements

I've got a simple parent child object stored as a document in MongoDB. Something simplistic like Order/OrderItems. (Order has an array of OrderItem)
What I'd like to do is query for a count of Order Items where they meet a set of criteria.
Example: In Order "999" find out how many order items had a quantity of 3.
db.collection.find( {OrderId:999, "OrderItems.QuantityOrdered":3} ).count();
The way this query works is it returns "1" because if it matches at least one OrderItem inside the array it will return the count of Orders matched.
How can I query for how many "OrderItems" matched?:
There's no direct way of return this sort of count with an embedded document. With this sort of ad-hoc count, your best bet is to return the document and do the count from the application.
If you want to perform this kind of count for a large number of orders, you could use map-reduce, which will output the results to a new collection.