【发布时间】:2020-07-19 18:35:49
【问题描述】:
我正在使用带有 Mongo DB 的sails JS。 我的模型是:
module.exports = {
attributes: {
title:{type:"string",required:true},
content:{type:"string",required:true},
date:{type:"string",required:true},
filename:{type:"string",required:true},
},
};
我的控制器是:
fetchposts:function(req,res){
console.log("in fetch posts")
mysort={$id:-1}
Cyberblog.find().sort(mysort).limit(5).exec(function(err, result) {
if (err || !result) {
message="no records fetched";
console.log(message);
res.redirect('/newpost');
}
else{
console.log(result)
}
我遇到了一个错误提示
“警告:提供的条件中的sort子句被指定为字典(普通JS对象),
这意味着它可能使用了 Mongo-Esque 语义(类似于{ fullName: -1, rank: 1 })。
但从 Sails v1/Waterline 0.13 开始,这不再是推荐的用法。相反,请使用
像'fullName DESC' 这样的字符串,或者像[ { fullName: 'DESC' } ] 这样的数组。
(既然我明白你的意思,暂时容忍并重新映射这种用法......)
我无法获取任何记录。它显示未获取任何记录。
所以我有一个关于排序的警告,并且没有来自数据库的记录。请帮我解决问题。
【问题讨论】:
-
我来这里是为了寻找与标题中引用的错误消息相关的信息,但问题似乎与标题中的错误无关。您能否更改标题以避免误导未来的搜索者?或者更改问题以明确与标题的关系?
标签: node.js mongodb sails.js sails-mongo