在MongoDB中进行升序排序时,结果是null和undefined首先是有值的字段。在Minimongo中进行升序排序时,结果是null首先是空的,然后是有值的字段,最后是未定义的字段。这种不同就是制造问题。有没有办法让MongoDB和Minimongo以同样的方式排序: null和undefined?

发布于 2020-01-09 11:30:20
这更多的是minimongo的问题,因为MongoDB发布了规范的BSON type sort order,并且已经使用这种类型排序很长时间了。
不幸的是,minimongo已经一年多没有更新了。
发布于 2020-01-13 23:46:48
如果在浏览器控制台中执行:
const test = new Mongo.Collection(null);
test.insert({foo: undefined});
test.insert({foo:'foo'});
test.insert({foo:null});
test.find({}, { sort: { foo: 1 } }).map(i => i.foo);它可以正确打印:[undefined, null, 'foo']。所以请提供复制品。
https://stackoverflow.com/questions/59643348
复制相似问题