mas*_*iny 0 python django mongodb
刚开始使用mongo db。
context = {}
if request.method == 'POST':
context['name'] = request.POST['name']
context['username'] = request.POST['username']
context['mobile'] = request.POST['mobile']
get = db.messages.find( { 'name' : request.POST['name'] } )
if get is not None:
print get.name
Run Code Online (Sandbox Code Playgroud)
我的数据库中有两条记录。
> db.messages.find()
{ "_id" : ObjectId("513f2cf1ae4cb53c1374b4f6"), "username" : "hello@gmail.com", "mobile" : "78978555", "name" : "rohit" }
{ "_id" : ObjectId("513f2cfeae4cb53c1374b4f7"), "username" : "hi@gmail.com", "mobile" : "8528522", "name" : "Rohti" }
Run Code Online (Sandbox Code Playgroud)
当我发布名称为rohit的表格时。我收到上述错误。
请告诉我在这里我可能做错了什么。
我知道我在mongo db中执行错误的查询。请帮助我回到正轨。
在pymongo中以光标形式获取返回值。
尝试:
for record in get:
print record['name']
Run Code Online (Sandbox Code Playgroud)
另外,get不是变量的好名字。
| 归档时间: |
|
| 查看次数: |
8700 次 |
| 最近记录: |