Pet*_*ete 5 mongoose node.js sails.js waterline
我想使用SailsJS" Find Where "蓝图路径创建一个包含多个条件的复杂查询.但是,我无法成功使用equals比较器和条件.我找不到关于如何实现Find Where路由的充分文档,因此我完成了源代码并提出了以下方案.
使用SailsJS Find Where Blueprint Route,如何实现:
以下方案将返回相应的响应:
http://localhost:1337/api/user?name=fred
http://localhost:1337/api/user?where={"name":{"startsWith":"fred"}}
http://localhost:1337/api/user?where={"name":{"endsWith":"fred"}}
http://localhost:1337/api/user?where={"name":{"contains":"fred"}}
http://localhost:1337/api/user?where={"name":{"like":"fred"}}
http://localhost:1337/api/user?where={"or":[{"name":{"startsWith":"fred"}}]}
http://localhost:1337/api/user?where={"or":[{"name":{"startsWith":"fred"}},{"path":{"endsWith":"fred"}}]}
Run Code Online (Sandbox Code Playgroud)
以下方案返回空响应:
http://localhost:1337/api/user?where={"name":{"equals":"fred"}}
http://localhost:1337/api/user?where={"name":{"=":"fred"}}
http://localhost:1337/api/user?where={"name":{"equal":"fred"}}
http://localhost:1337/api/user?where={"and":[{"name":{"startsWith":"fred"}}]}
http://localhost:1337/api/user?where={"and":[{"name":{"startsWith":"fred"}},{"path":{"endsWith":"fred"}}]}
Run Code Online (Sandbox Code Playgroud)
要使用"和"查询,请使用&符号一起使用查询字符串语法和链标准.对于更高级的查询,如OR复杂的运算符,最好编写一个控制器动作.如果您决定坚持使用蓝图,则可以使用编码为JSON的大多数有效Waterline查询.
对于简单查询,您使用查询字符串方法.以下将为姓名和学校构建"和"查询.
http://localhost:1337/api/user?name=fred&school=foo
Run Code Online (Sandbox Code Playgroud)
要将更高级的运算符链接在一起,以下应该可以工
http://localhost:1337/api/user?where={"name":{"startsWith":"fred"},"path":{"endsWith":"fred"}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2001 次 |
| 最近记录: |