Created
July 10, 2013 19:47
-
-
Save t0ster/5969577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
import pymongo | |
client = pymongo.MongoClient() | |
db = client.test_database | |
if not db.users.count(): | |
db.users.insert({ | |
'first_name': 'John', | |
'last_name': 'Smith' | |
}) | |
db.users.insert({ | |
'first_name': 'Tom', | |
'last_name': 'Taylor' | |
}) | |
result = client.test_database.users.aggregate([ | |
{"$project": { | |
"full_name": {"$concat": ["$first_name", " ", "$last_name"]} | |
}}, | |
{"$sort": {"full_name": 1}} | |
]) | |
pprint(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment