简体   繁体   中英

I can not sort the data alphabetically with neDB database

it turns out that I have a problem with a database that I am using in electron with the neDB module. The problem I have is that it does not sort the values alphabetically if the field starts with a capital letter.

When I try to sort them in alphabetical order they come out completely disorganized. I have saved all the names in the database without uppercase and it orders them perfectly, it is a problem with the beginning of name with uppercase letter.

I tried to search the network if there was someone with the same problem and it seems that I have not found anyone. Maybe I'm doing something wrong

var db= new Datastore({filename: path.normalize(
        app.getPath('userData'))+'/base/people.db',
        autoload:true});

db.find({}).sort({'nom' : 1 }).skip(0).limit(15).exec(function (err, docs) {

        docs.forEach(function(doc, i, arr){



    var divNombre = document.createElement('div');

        divNombre.className='nombre';

        divFicha.appendChild(divNombre); 

    var textoNombre = document.createTextNode(doc.nom);

        divNombre.appendChild(textoNombre);


        });//docs.forEach(function(doc, i, arr)



    });

Small example of the database:

{"nom":"tpaggtff","iu":"5r55rr5rf","des":"fffffffffffff"_id":"2899ts0q","ba":"no"}
{"nom":"astohgff","idF":"5t554545","des":"frfrfrcrfrrrf","_id":"3omnamvi","ba":"no"}
{"nom":"Bettgnhitoz","idF":"dededed","des":"ddffff55f","_id":"au0oxhxy","ba":"no"}

The result of executing your data is :

[ { nom: 'Bettgnhitoz',
    idF: 'dededed',
    des: 'ddffff55f',
    ba: 'no',
    _id: 'cDeLArtZYkVCHI7e' },
  { nom: 'astohgff',
    idF: '5t554545',
    des: 'frfrfrcrfrrrf',
    ba: 'no',
    _id: 'oC4CIUmxJ2kqHcMC' },
  { nom: 'tpaggtff',
    iu: '5r55rr5rf',
    des: 'fffffffffffff',
    ba: 'no',
    _id: 'CLucpeOhxsnSUua6' } ]

Which is accurate as the uppercase letters will be sorted before the smaller case letters, this is due to the order of the characters in the ASCII character set, check this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM