ptwobrussell / Mining-the-Social-Web-2nd-Edition

The official online compendium for Mining the Social Web, 2nd Edition (O'Reilly, 2013)
http://bit.ly/135dHfs
Other
2.9k stars 1.49k forks source link

Mongo collection name in Twitter Chap 9, Example 22 #280

Open billsanto opened 9 years ago

billsanto commented 9 years ago

Leading the collection name with a number (twitter id) is problematic when using the mongo shell. So the following: '{0}-follower_ids'.format(fid))

should be changed to something like: 'followerids{0}'.format(fid))

Also the period should be changed to an underscore, or removed. Failing to do either leads to one of two errors:

config:[mongodb followers_crawl] > db.164237500-follower-ids.find() 2015-08-10T10:46:23.798-0500 E QUERY SyntaxError: Unexpected number config:[mongodb followers_crawl] > db.164237500_follower_ids.find() 2015-08-10T10:46:50.516-0500 E QUERY SyntaxError: Unexpected token ILLEGAL config:[mongodb followers_crawl] > db.followerids.164237500.find() 2015-08-10T10:49:16.215-0500 E QUERY SyntaxError: Unexpected number

If a collection is inappropriately named, then the workaround is: config:[mongodb followers_crawl] > db['164237500-follower-ids'].find()

But it can be preferable to start over and drop the collection: config:[mongodb followers_crawl] > db['164237500-follower-ids'].drop()

Finally, this syntax works:

config:[mongodb followers_crawl] > db.follower_ids_164237500.find()

Have not yet tried to see if the pymongo driver has an issue with retrieving a name with one of these issues.

See: http://stackoverflow.com/a/14143147