New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MongoFrames doesn't delete document #13
Comments
Hi @njordr - we use the delete function quite a bit and clearly it passes the tests currently so my guess would be that this is specific to your scenario, like you highlight I'd typically expect this to be done like so: SDClosetLogs().by_id(log_id).delete() If this isn't working then it sounds like the something specific to the |
This is my SDClosetLogs class
|
@njordr - maybe it's an issue setting the |
I set the _id field manually |
OK I'll make sure I do also, are you storing an ObjectID as the ID or are just a hash string? |
hash string |
@njordr - So the following code sample works correctly for me, can you confirm it works for you or if it raises an error to help track the source of the issue? from pymongo import MongoClient
from mongoframes import Frame
# Connect to database via MongoFrames
Frame._client = MongoClient(
'mongodb://localhost:27017/njordr_test'
)
# Define the docyment
class SDClosetLogs(Frame):
_db = 'spy'
_collection = 'logs'
_fields = {
'_id',
'date',
'type',
'subtype',
'installation',
'closet',
'shelf_event',
'tag_id',
'tag_user',
'description',
'counter'
}
# Insert a document
document = SDClosetLogs(
_id='c4e599fb7467db9f868746631b7daea81a32fc63a2be05871b5710d8',
date='2016-12-11',
type='foo',
subtype='bar',
installation=True,
closet=False,
shelf_event=True,
tag_id='746631b7daea81a32fc63a2be05871b5710d8c4e599fb7467db9f868',
tag_user='Ad8c4e599fb7467db9f746631b7daea81a32fc63a2be05871b5710d8',
description='MongoFrames is a fast unobtrusive MongoDB ODM for Python \
designed to fit into a workflow not dictate one.',
counter=1
)
document.insert()
# Check a document was inserted
print(SDClosetLogs.count())
# Find and delete the same document
document_ref = SDClosetLogs.by_id(document._id)
try:
document_ref.delete()
except Exception as e:
print(e)
# Check the document was deleted
print(SDClosetLogs.count()) |
The result should of course print out:
|
it works, I need to recheck carefully my code. many thanks for your time |
No problem, let me know how you get on and if I can help further :) |
Stupid bug: I used the same code to update or delete a record: it didn't exit in case of delete, so it re-create the document (the right way in case of update task) |
Hi.
A strange issue: the Frame class doesn't delete the document from the db. Insert and update works fine.
This is the log:
2016-12-11 16:30:36 DEBUG 3700 spy_replicator.etl_modules.etl_spydoc etl_spydoc.py:219 => Deleting document c4e599fb7467db9f868746631b7daea81a32fc63a2be05871b5710d8. (no exception logged)
I tried using both the previous_record instance and the general Frame class.
This is the documents in collections pre and after the delete operation:
This is the Frame class
The text was updated successfully, but these errors were encountered: