mongodb里如何对数字字符串进行排序

2025-05-02 10:22:45
推荐回答(2个)
回答(1):

MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型。

回答(2):

example = {_id: "XXX", text: "YYY"}

db.example.aggregate([
{$project : {text : 1, length : {$size : "$text"}}},
{$sort : {length : 1}}
]);
I think this will do the job, but only for mongo 2.6 and above