schapman1974 / tinymongo Goto Github PK
View Code? Open in Web Editor NEWA simple wrapper to make a flat file drop in raplacement for mongodb out of TinyDB
License: MIT License
A simple wrapper to make a flat file drop in raplacement for mongodb out of TinyDB
License: MIT License
pymongo supports accessing to the databases and collections dynamically by means of a subscription instead of attribute reference.
When using the example code in Python 3.8 i get this error :
Traceback (most recent call last):
File "C:/Users/loicn/backend_db.py", line 7, in <module>
db = connection.my_tiny_database
File "C:\Users\loicn\AppData\Local\Programs\Python\Python38\lib\site-packages\tinymongo\tinymongo.py", line 73, in __getattr__
return TinyMongoDatabase(name, self._foldername, self._storage)
File "C:\Users\loicn\AppData\Local\Programs\Python\Python38\lib\site-packages\tinymongo\tinymongo.py", line 73, in __getattr__
return TinyMongoDatabase(name, self._foldername, self._storage)
File "C:\Users\loicn\AppData\Local\Programs\Python\Python38\lib\site-packages\tinymongo\tinymongo.py", line 73, in __getattr__
return TinyMongoDatabase(name, self._foldername, self._storage)
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded
Process finished with exit code 1
The collection.drop()
method is not yet implemented. Here's the reference link: https://docs.mongodb.com/manual/reference/method/db.collection.drop/
The current github version is so much better than what's on PyPI.
Really should be pushed soon.
For consistency,
pymongo ref:
pymongo.results.InsertOneResult(inserted_id, acknowledged)
This project looks great. Any idea or plans on allowing it to be the backend for higher level libraries like MongoEngine, uMongo?
It seems like it might be possible to just replace MongoClient() with TinyMongoClient() in some way and potentially ignore things like create index requests if that isn't supported.
For consistency,
pymongo ref:
pymongo.results.InsertManyResult(inserted_ids, acknowledged)
Tries running code from "examples" section, got RecursionError
from tinymongo import TinyMongoClient
>>> connection = TinyMongoClient()
>>> db = connection.my_tiny_database
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/whatever/my_project/.venv/lib/python3.8/site-packages/tinymongo/tinymongo.py", line 73, in __getattr__
return TinyMongoDatabase(name, self._foldername, self._storage)
File "/Users/whatever/my_project/.venv/lib/python3.8/site-packages/tinymongo/tinymongo.py", line 73, in __getattr__
return TinyMongoDatabase(name, self._foldername, self._storage)
File "/Users/whatever/my_project/.venv/lib/python3.8/site-packages/tinymongo/tinymongo.py", line 73, in __getattr__
return TinyMongoDatabase(name, self._foldername, self._storage)
[Previous line repeated 987 more times]
RecursionError: maximum recursion depth exceeded
TinyMongo should enforce using ObjectId, just like MongoDB does.
The bson ObjectId can't be used directly, because it doesn't accept TinyDB ids (they are too short). So either make the TinyDB id the right size, or implement own ObjectId:
class ObjectId:
def __new__(cls, *args, **kwargs):
return str(args[0])
Hi, I see that https://pypi.python.org/pypi/tinymongo is 0.1.3 and master is 0.1.6
(with new changes going to 0.1.7?)
When new releases is going to PyPI?
Thanks
The way setup.py is written, the project will install correctly directly, and straight from source, but I have an issue using tinymongo with test_requires
error: [Errno 2] No such file or directory: 'requirements.txt'
Though the requirements are passed correctly inside the dist (tinymongo.egg-info/requires.txt
) this isn't accessible at setup time. And when pytest tries to get set up, it fails because of requirements.txt
Hard-writing the requirements.txt into setup.py (rather than reading from requirements.txt) would fix this. Or also checking the .egg-info path might do the trick too.
By the way, I'm a big fan of this project as the noSQL alternative to SQLite project.
I kept wondering why when I used "$unset" nothing was changed. Then I checked the tests, and then finally drilled into the code and noticed that "$unset" is not implemented.
Are there any plans for adding this?
TinyMongo allows you to update a document like this:
collection.update_one({"_id": "fh98h43f89fh4fh"}, {"some_field": "some update"})
But on the real MongoDB database (on mLab) I get this error: ValueError: update only works with $ operators
.
So I needed to change the code like this:
collection.update_one({"_id": "fh98h43f89fh4fh"}, {"$set": {"some_field": "some update"}})
This also works on TinyMongo and it is a more appropriate way to update a document. TinyMongo should follow the MongoDB/pymongo behaviour and throw the same error in the first case.
This is a question rather than an issue, as I could not find an answer.
Does tinymongo support multithreading and if not, can I use it in conjunction with tinyrecord module?
I would like to store values in database performing inserts and updates from threads while being able to use Flask-Admin interface to perform UI CRUD operations.
I have a document like this
{
'_id': '3c7df42e91c611e7bf575ce0c5482b4b',
'authors': ['Bruno Rocha'],
'authors_slug': ['bruno-rocha'],
'category': 'python/flask',
'date': datetime.datetime(2017, 9, 4, 20, 10, 26),
'published': True,
'slug': 'simple-login-extension-for-flask',
'tags': ['python', 'flask', 'pythonplanet', 'pyplanet', 'new'],
'title': 'Simple Login Extension for Flask',
}
It has a 'tags': ['python', 'flask', 'pythonplanet', 'pyplanet', 'new']
and I have more documents with tag python
When I search using {'tags': 'python'}
col.find({'tags': 'python'}).count()
25.09 22:19:22 tinymongo.tinymongo DEBUG query to parse2: {'tags': 'python'}
25.09 22:19:22 tinymongo.tinymongo DEBUG query: {'tags': 'python'} prev_query: None
25.09 22:19:22 tinymongo.tinymongo DEBUG conditions: tags python
25.09 22:19:22 tinymongo.tinymongo DEBUG c: QueryImpl('==', ('tags',), 'python')
25.09 22:19:22 tinymongo.tinymongo DEBUG new query item2: QueryImpl('==', ('tags',), 'python')
0
Ok that is expected so lets use {'$in': 'python'}
col.find({'tags': {'$in': 'python'}}).count()
25.09 22:20:34 tinymongo.tinymongo DEBUG query to parse2: {'tags': {'$in': 'python'}}
25.09 22:20:34 tinymongo.tinymongo DEBUG query: {'tags': {'$in': 'python'}} prev_query: None
25.09 22:20:34 tinymongo.tinymongo DEBUG conditions: tags {'$in': 'python'}
25.09 22:20:34 tinymongo.tinymongo DEBUG c: None
25.09 22:20:34 tinymongo.tinymongo DEBUG query: {'$in': 'python'} prev_query: tags
25.09 22:20:34 tinymongo.tinymongo DEBUG conditions: $in python
25.09 22:20:34 tinymongo.tinymongo DEBUG c: None
25.09 22:20:34 tinymongo.tinymongo DEBUG new query item2: None
0
or with a list: {'$in': ['python', 'flask']}
col.find({'tags': {'$in': ['python', 'flask']}}).count()
25.09 22:21:09 tinymongo.tinymongo DEBUG query to parse2: {'tags': {'$in': ['python', 'flask']}}
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'tags': {'$in': ['python', 'flask']}} prev_query: None
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: tags {'$in': ['python', 'flask']}
25.09 22:21:09 tinymongo.tinymongo DEBUG c: None
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'$in': ['python', 'flask']} prev_query: tags
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: $in ['python', 'flask']
25.09 22:21:09 tinymongo.tinymongo DEBUG c: None
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'tags': 'python'} prev_query: None
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: tags python
25.09 22:21:09 tinymongo.tinymongo DEBUG c: QueryImpl('==', ('tags',), 'python')
25.09 22:21:09 tinymongo.tinymongo DEBUG query: {'tags': 'flask'} prev_query: None
25.09 22:21:09 tinymongo.tinymongo DEBUG conditions: tags flask
25.09 22:21:09 tinymongo.tinymongo DEBUG c: QueryImpl('==', ('tags',), 'flask')
25.09 22:21:09 tinymongo.tinymongo DEBUG new query item2: QueryImpl('or', frozenset({('==', ('tags',), 'python'), ('==', ('tags',), 'flask')}))
0
I checked the source code and currently the $in
operator only works in the reverse
way, it works currently to match a single field against an array of possibilities. But not to check an array against a single value or array.
This is a named parameter, so name compatibility is required
Your code:
record_id = collection.insert_one({'username': 'admin', 'password': 'hello world'}) user_info = collection.find_one({'_id': record_id})
But record_id is an <tinymongo.results.InsertOneResult object>
I read some code. I think it should be
record_id = collection.insert_one({'username': 'admin', 'password': 'hello world'}).inserted_id
Tested in Python 3.6.1.
Hello! Thanks for the great lib ^_^
I've been testing a bit the examples,
and found out that
# Getting the total of records
db.users.count()
in the README doesn't work for me, while db.users.find().count()
does.
Am I doing something wrong or is the docs to fix?
Thank you,
have the greatest day
Not sure how to implement other than taking .keys()
of the top-level of the JSON.
Your code:
db.users.count()
I think it should be:
db.users.find().count()
def count():
if self.table is None: self.buildTable()
return self.table.count(self.lastcond)
This project had a lot of potential but since it's not maintained anymore (e.g. broken with TInyDB 4), https://github.com/davidlatwe/montydb seems very promising
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.