example is given from flask framework
@app.route('/json', methods=['GET', 'POST'])
def json_data():
return Company.objects.all().to_json()If you want to convert json data into mongodb object try this
c = Company.objects.from_json(company)
@app.route('/json', methods=['GET', 'POST'])
def json_data():
return Company.objects.all().to_json() c = Company.objects.from_json(company)
SELECT Firstname,Lastname FROM Users
WHERE City IN ('Tbilisi','London');
{
"_id" : ObjectId("51f80e4ba44433577cb1bdbc"),
"Firstname" : "Leqso",
"Lastname" : "Zazikashvili",
"City" : "Tbilisi",
"Languages" : [
"English",
"Spanish",
"German"
]
}
Now lets write query to fetch all entries from mongodb where the City is Tbilisi or London
db.users.find(
{ City: {$in:["Tbilisi","London"]} })
As we can see $in operator selects the entries where the field value equals any value in the specified array. We can also get this entries from subarray.This will fetch all entries where subarray of languages contains "Chinese" or "Spanish"
db.users.find(
{ Languages: {$in:["Chinese","Spanish"]} }
)