0
我是新來的MongoDB和RestFul網絡services.from下面的代碼,我從我的本地服務器獲取結果。pymongo身份驗證用戶憑據
import pymongo
conn=pymongo.MongoClient()
db = conn['restaurant'] # DB Name.
@csrf_exempt
@api_view(['GET'])
def getAllRestaurants(request):
rests = []
coll = db['Restaurants'] # Collection Name.
if request.method == 'GET':
all = coll.find({"isActive":True})
for each in all:
json_data = ({"_id":str(each['_id']),'name': each['name']})
rests.append(json_data)
data = {"allRestaurants": rests}
return JSONResponse(data)
GET - http://127.0.0.1:8000/restaurant/getAllRestaurants/
{ 「allRestaurants」:[ { 「_id」: 「579b032ee4b048c9b19d887c」, 「名稱」: 「XXXXX」 }, { 「_id」: 「579b032ee4b048c9b19d887d」, 「名稱「:」yyyyy「 }]}
到此爲止它的罰款。
當我嘗試連接遠程服務器,其給予身份驗證錯誤。 我知道用戶名和密碼,但我不知道如何使用和在pymongo模塊中使用。 我的遠程服務器也有相同的數據庫名稱和集合。
想我登錄:測試和密碼:測試那麼如何連接到與pymongo模塊遠程服務器。 如果我在這裏錯了,請糾正我。