小编Pil*_*ila的帖子

在MongoDB中对子文档进行排序

有没有办法在mongo查询中对子文档进行排序?示例(博客集合):

{
    "_id" : ObjectId("4c69d19532f73ad544000001"),
    "content" : "blah blah blah",
        "comments" : {
{"author": "jim",   "content":"comment content 1", "date" : "07-24-1995"},
{"author": "joe",   "content":"comment content 2",  "date" : "07-24-1996"}
{"author": "amy", "content":"comment content 3", "date" : "09-10-1999"}
        }
}
{
    "_id" : ObjectId("4c69d19532f73ad544000002"),
    "content" : "blah blah blah",
        "comments" : {
{"author": "jim",   "content":"comment content 1",  "date" : "07-24-1995"},
{"author": "joe",   "content":"comment content 2",  "date" : "07-24-1996"}
{"author": "amy", "content":"comment content 3",  "date" : "07-24-1997"}
        }
}
Run Code Online (Sandbox Code Playgroud)

我希望按照我决定的方式订购我的博客文章,然后在我的博客帖子中通过按日期反向排序或我想要的任何其他排序来订购评论.这可能与mongoDB有关吗?

sorting document mongodb

14
推荐指数
1
解决办法
9912
查看次数

在 pythonanywhere 上托管使用 redis 的 Django 项目

我在本地笔记本电脑上开发了一个电子商务网站,该项目使用了redis当我从本地主机运行该项目时,它使用以下命令完美运行 r = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=settings.REDIS_DB)

REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_DB = 1
Run Code Online (Sandbox Code Playgroud)

现在,我正在尝试将项目部署到任何地方的 python 上。我已经安装了redis并启动了服务器,更改localhostmyhost.pythonanywhere.com但是当我运行访问该站点时出现以下错误:

Error 111 connecting to 50.19.109.98:6379. Connection refused.
Request Method: GET
Request URL:    http://myhost.pythonanywhere.com/en/4/black-garbage-t-shirt/
Django Version: 1.8.3
Exception Type: ConnectionError
Exception Value:    
Error 111 connecting to 50.19.109.98:6379. Connection refused.
Exception Location: /home/dguy/dguy/venv/lib/python3.4/site-packages/redis/connection.py in connect, line 436
Python Executable:  /usr/local/bin/uwsgi
Python Version: 3.4.3
Python Path:    
['/var/www',
 '.',
 '',
 '/var/www',
 '/home/dguy/dguy/venv/lib/python3.4',
 '/home/dguy/dguy/venv/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/dguy/dguy/venv/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/dguy/dguy/venv/lib/python3.4/site-packages',
 '/home/dguy/dguy',
 '/home/dguy'] …
Run Code Online (Sandbox Code Playgroud)

django redis pythonanywhere

1
推荐指数
1
解决办法
2271
查看次数

标签 统计

django ×1

document ×1

mongodb ×1

pythonanywhere ×1

redis ×1

sorting ×1