简体   繁体   English

我无法使用neDB数据库按字母顺序对数据进行排序

[英]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. 事实证明,我使用neDB模块在电子中使用的数据库有问题。 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 . 这是正确的,因为大写字母将在小写字母之前排序,这是由于ASCII字符集中的字符顺序所致,请检查此项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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