July 2017
Intermediate to advanced
374 pages
8h
English
This function adds new tweets from an existing user.
In this case, we need to modify our add_tweet(new_tweet) method to interact with users, and the tweets collection in MongoDB to add new tweets, as follows:
def add_tweet(new_tweet):
api_list=[]
print (new_tweet)
db_user = connection.cloud_native.users
db_tweet = connection.cloud_native.tweets
user = db_user.find({"username":new_tweet['tweetedby']})
for i in user:
api_list.append(str(i))
if api_list == []:
abort(404)
else:
db_tweet.insert(new_tweet)
return "Success"
Now that we have modified the record, let's test it out. The following screenshot shows the success status of the POST request to add new tweets using POSTMAN:
Let's now validate whether the newly added ...