Monday, 15 February 2010

sorting - MongoDB sort does not work -


From this morning (I think) I can not sort my collection in the collection, in 26 9 44 objects are present (this current My biggest is - but the reason is not correct?).

So what am I doing:

  myCollection.find () .sort ({_id: 1})  

Works great and without any problem! But:

  myCollection.find (). Sort ({xxx: 1})  

Do not work in each other's case, xxx means any other key on my purpose does not matter what I take ... For example:

  myCollection.find ({revised: {$ exists: true}})  

returns a result with 26 9 44 objects Is,

  myCollection.find ({revised: {$ exists: true}}). Sort ({"Revised": - 1})  

0 objects will return.

Did I do something wrong? Maybe I had my collection crashed? What can anyone do in this case? (Archive example excepts)

To leave the object:

  { "_id": ObjectId ( "55071e25760e250d050ed8d5"), "sysModified": new Date ( "2015- 03- New date (1426528563945), "payment": [], "order items": [["order number": 'xxxxx', '15' 21: ​​10: 12 + 0100), "created": new "Price": 1, "name": "xxxxxxx", "VAT": 19, "Date" (1426529829 9 22), "Modified", "Currency": "European", "Christian": "xxxxx" "Quantity": 1 29.989999999999998437, "currency": "EUR" "_id": Objektaidi ( "5507365c89866d820dcef7e0"),}, { "orderId": 'XXXxx', 'itemId': 'XXXxx', "ean": "xxxxx" "volume": 1, "name": "xxxxxxx" "order": {"orderId": "VAT": 19, "value": 29.989999999999998437, "currency": "EUR", "_id": object Taidi ( "5507365c89866d820dcef7e1"),}], "order": XXXXXXXXX, "order": "Order", "status": "XXXXXXXXX", "Taimstamp_afpi" XXXXXXXXX "Customer": XXXXXXXXX, ...}, " order delivery status ": {" client ": XXXxxxxxxxx," company "" XXXXXXxxxx "," XXXXXXxxxx "," street ":" xxxxxxxxxxx "," houseNumber ":" xxxxxxxxxxx "," zip ":" Xxxxxxxxxxx "" "" "extra": "", "Prthamnam": "Xxxxxxxxxxx", "name", "city": "Xxxxxxxxxxx", "Iso2": "Xxxxxxxxxxx", "phone": "Xxxxxxxxxxx", "fax": "xxxxxxxxxx "", "Email": "xxxxxxxxxxx", "order customer records": {"Customer": XXXXXXxxxx, "Company": "", "Extra": "", "First name": "xxxxxxxxxxx", "Alias" : "Xxxxxxxxxxx", "street": "xxxxxxxxxxx", "houseNumber ":" Xxxxxxxxxxx "" Zip ":" xxxxxxxxxxx "," City ":" xxxxxxxxxxx "," iso2 ":" xxxxxxxxxxx "," phone ":" xxxxxxxxxxx "," fax ":" XXXxxxx Xxxxxxxxxxxxx "," __v ": 1}  

It is It is possible that your collection is large If you try to sort this on a key, then there is no index, resulting in a large number of results. The error should look like this:

  Error: {"$ err": "Too many data to sort without indexing.) Add an index or specify a small limit", " Code ": 10128}  

What can you do that you can add an index based on your key:

  db.myCollection.ensureIndex ( {"Modified": -1})  

Or you reduce the results before sorting:

  myCollection.find ({revised: {$ Exists: true}}) .limit (10) .sort ({"revised": - 1})  

No comments:

Post a Comment