Proyection 不适用于 sort in sails
Proyection don't works with sort in sails
为什么在 sails 中使用排序时,proyections 不起作用。
Command.find({},{parameter:true, value: true, _id: false, finalDate:true}).sort('finalDate ASC').exec(function(error, cmd){}
您在哪里找到 projections
文档?据我所知,projections
在 Waterline 中不可用。
Here 是答案
When you use Sort() this disable proyection.
当您使用 Waterline 时,您不会直接与 sails-mongo 驱动程序交互。 Waterline 是一种与适配器无关的抽象,它允许使用特定接口构建适配器。
当前的查找方法只接受条件对象,不接受投影对象。这是因为 Waterline 中的 find 方法不仅必须与 sails-mongo 一起工作,而且还必须与 sails-mysql、sails-postgresql、sails-redis 等一起工作
在下一个 Waterline 版本 0.10 中,我想向查询构建器引入一个 select 选项,以允许在所有适配器上完成此类事情。
同时,如果您想要投影,您可以使用本机方法访问直接 mongo 驱动程序:
// 获取 mongo-driver
的一个实例
User.native(function(err, collection) {
// Execute any query that works with the mongo js driver
collection.find(criteria, projection).sort(sort).toArray(function(err, docs) {
console.log(users);
});
});
为什么在 sails 中使用排序时,proyections 不起作用。
Command.find({},{parameter:true, value: true, _id: false, finalDate:true}).sort('finalDate ASC').exec(function(error, cmd){}
您在哪里找到 projections
文档?据我所知,projections
在 Waterline 中不可用。
Here 是答案
When you use Sort() this disable proyection.
当您使用 Waterline 时,您不会直接与 sails-mongo 驱动程序交互。 Waterline 是一种与适配器无关的抽象,它允许使用特定接口构建适配器。
当前的查找方法只接受条件对象,不接受投影对象。这是因为 Waterline 中的 find 方法不仅必须与 sails-mongo 一起工作,而且还必须与 sails-mysql、sails-postgresql、sails-redis 等一起工作
在下一个 Waterline 版本 0.10 中,我想向查询构建器引入一个 select 选项,以允许在所有适配器上完成此类事情。
同时,如果您想要投影,您可以使用本机方法访问直接 mongo 驱动程序:
// 获取 mongo-driver
的一个实例User.native(function(err, collection) {
// Execute any query that works with the mongo js driver
collection.find(criteria, projection).sort(sort).toArray(function(err, docs) {
console.log(users);
});
});