Skip to content

Instantly share code, notes, and snippets.

@t0ster
Created July 10, 2013 19:47
Show Gist options
  • Save t0ster/5969577 to your computer and use it in GitHub Desktop.
Save t0ster/5969577 to your computer and use it in GitHub Desktop.
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