question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how can i order in db

See original GitHub issue

Hi : Mauricio thanks for your project first . i have a doubt that why there is no order in Find

IEnumerable<T> Find(Query query, int skip = 0, int limit = int.MaxValue)

for example , i want take latest 100 docs , i have a field “AddedTime” the normal way is order by AddedTime desc then skip 0 and take(limit) 100 ,that’s what i needed . but without order ,the take is no sence .

what should i do ?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
mbdavidcommented, May 25, 2015

Hi @178220709,

If you want take your lasted 100 docs using indexes, you can:

  1. Create an index on AddedTime
  2. Run `collection.Find(Query.All(“AddedTime”, Query.Descending), 0, 100);

Now you will list all yor documents in AddedTime desc order and get only 100 first.

0reactions
mbdavidcommented, May 28, 2015

You right, local db has no network and all operations must be executed in local machine.

The only optimization that can be do it is filter. So, Find operation use indexed document field. This is valid optimation. When you use Query.All and than implement a Where linq, it´s more expensive because you need read all data pages and deserialize all documento only to know if match with your clause.

So, my recomendation is: always use Find (when possible) and then use normal Linq implementation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to store ordered information in a Relational Database
A column called order , which is a decimal ( NUMERIC ). When a song is moved, it is assigned the floating point...
Read more >
Storing item positions (for ordering) in a database efficiently
Store the order linked-list style. Instead of saving the absolute position, save the ID of the previous item. That way any change only...
Read more >
SQL ORDER BY Keyword
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword....
Read more >
How to Order Alphabetically in SQL
If you want to select records from a table but would like to see them sorted according to a given column, you can...
Read more >
ORDER BY - MariaDB Knowledge Base
Use the ORDER BY clause to order a resultset, such as that are returned from a SELECT statement. You can specify just a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found