tag:blogger.com,1999:blog-18508356.post2960147252637298718..comments2026-02-13T11:24:21.556-05:00Comments on Just a little Python: Getting Started with MongoDB and PythonRick Copelandhttp://www.blogger.com/profile/11612114223288841087noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-18508356.post-35493698534413550762016-02-01T14:55:27.167-05:002016-02-01T14:55:27.167-05:00My experience with MongoDB has generally used it a...My experience with MongoDB has generally used it as the main data store for a new application. Migrations, when they happened, were typically Python scripts that extracted data from one source and inserted it into the database. In some cases it was CSV data, in others it was result sets from queries in MySQL or Postgres databases.Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-91251860643618066012016-02-01T13:21:34.071-05:002016-02-01T13:21:34.071-05:00Rick, thanks for replying so quickly. Would you m...Rick, thanks for replying so quickly. Would you mind sharing, what method have you used in your real world projects to get the information into MongoDB? What physical form did the original info that you had to deal with come in and how did you dump it in the collection?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18508356.post-78262836238101071962016-02-01T07:27:40.532-05:002016-02-01T07:27:40.532-05:00MongoDB "documents," as it seems you'...MongoDB "documents," as it seems you've discovered, are completely different from Word documents. Since MongoDB stores structured data (JSON/BSON), extracting the structure you're looking for in a pile of unstructured Word documents is something you'd have to configure manually, maybe with an ETL tool (I don't really know much about the market there) or some manual coding.<br /><br />For Excel documents, the story is a little better, as at least Excel has rows and columns, which can be exported as a CSV file. CSV files can then be imported using the mongoimport (I think that's the name) tool that comes with the MongoDB distribution. Of course, what you end up with there is documents that look a whole lot like table rows, since they actually came from spreadsheet rows.<br /><br />Hope this helps!Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-68620413977905443302016-01-31T22:27:48.101-05:002016-01-31T22:27:48.101-05:00Sorry for such a real basic question here, but I&#...Sorry for such a real basic question here, but I'm trying to find some real world examples of how people actually get a pile of documents (physical documents like word docs or excel sheets) into a MongoDB collection. I've read a lot of articles that demonstrate how you can manually code information with JSON syntax using the doc ID, first name field and value, last name filed and value, etc. But, if I've got a folder full of say 10,000 word docs with customer info in each one and I want to be able to query that pile of docs and pull up say a result set that contains all customers from Iowa, how would I do that? How are all those documents parsed into JSON and then dumped into document objects into the collection? Is there some ETL type of program that does that? (and if so, what would it be?) I've googled like crazy trying to find an answer to that, but come up with zilch. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18508356.post-75949409007479360232012-12-13T11:28:16.989-05:002012-12-13T11:28:16.989-05:00Cool tool, Bob. Thanks for the comment!Cool tool, Bob. Thanks for the comment!Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-33172634550516539902012-12-13T11:25:26.063-05:002012-12-13T11:25:26.063-05:00Cool rundown, thanks Rick! In case anyone who is ...Cool rundown, thanks Rick! In case anyone who is learning MongoDB finds it useful, I just launched a free tool called querymongo.com that translates MySQL syntax into MongoDB syntax. Hope someone can use it to get up to speed faster!Bobhttp://www.querymongo.com/noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-24764984557522668442012-07-22T14:09:42.529-04:002012-07-22T14:09:42.529-04:00Glad to help!Glad to help!Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-51707613409134571732012-07-22T13:20:23.032-04:002012-07-22T13:20:23.032-04:00Ah, I worked out the "perfect match" ju...Ah, I worked out the "perfect match" just after posting this. My fault for trying to do things in a rush. Then I spent a while looking for how to use regexes. <br /><br />that did the job and got me a bit further on. <br /><br /><br />Many Thanks.BAdjao B And Bhttps://www.blogger.com/profile/11330042575905359270noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-59693210248667881882012-07-22T10:11:23.662-04:002012-07-22T10:11:23.662-04:00Thanks for the comment. I'm sorry if the examp...Thanks for the comment. I'm sorry if the example was confusing. The example I used was looking for blog articles with an *exact match* with one of the app_config_ids passed in.<br /><br />$in is always looking for an exact match in a list. If you want to find a partial match (such as a prefix), you need to use either $regex or a compiled python regular expression. For instance, if you're trying to find the articles starting with 'Hadoop', the query would be<br /><br />articles.find({'title': {'$regex': '^Hadoop.*'}})<br /><br />Again, sorry for the confusion. I'll try to be more explicit in the future. Thanks again for commenting.Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-21719443912866861342012-07-22T09:20:10.978-04:002012-07-22T09:20:10.978-04:00Warning to others
blog_post.find({'state'...Warning to others<br /><br />blog_post.find({'state':'published','app_config_id':{'$in':app_config_ids}})<br /><br />I just wasted an hour to find this syntax does not work.<br /><br />I have a collection "articles" with a field "title" and one document with title<br />"Hadoop Development Environment OS X"<br /><br />these work<br /><br />temp = articles.find({"title": "Hadoop Development Environment OS X"});<br /><br />temp = articles.find({"title":{"$in":["Hadoop Development Environment OS X"]}})<br /><br />This returns nothing.<br /> keys = ["Hadoop"]<br /> temp = articles.find({"title":{"$in":keys}})<br /><br />i.e all I can get back os a perfect match not a partial match.<br /><br />Either I am misunderstanding, but I worked form an internet example the author said works fine, or there is a problem with the driver. <br /><br />I am fairly confident I did not misunderstand the mongo docs.BAdjao B And Bhttps://www.blogger.com/profile/11330042575905359270noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-27276899796808415862012-01-18T13:15:03.506-05:002012-01-18T13:15:03.506-05:00FYI I deleted the user and DB I used in the post, ...FYI I deleted the user and DB I used in the post, so don't go trying any funny business ;-).Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.com