Skip to content

[PR] #805: Minor modifications to support disk-based stores #182

@engFelipeMonteiro

Description

@engFelipeMonteiro

The main change introduced in this PR is to explicitly assign an updated document to the collection store:

self._store[existing_document['_id']] = existing_document

This allows me to efficiently implement a disk-based store which always returns in-memory copies of the document dictionary which, therefore, cannot be updated simply by mutating (which is the assumption of the _update method). I recognise this isn't the target use case for mongomock but I hope you'll consider adding it as it's a fairly minor change (and touches upon - but doesn't fix - some of the immutability issues discussed in previous PRs e.g. mongomock#692 ).

The other changes are really just there to avoid creating a new list just to count the number of matching documents, which is particularly important in my use case but would generally benefit mongomock in any case.

Commit msg:
Previously when performing update operations the document dictionary would be updated in-place (and rolled back if need be, say on conflict). This approach makes it difficult to implement a store where the documents are not in-memory, for example, stored on disk. In this case, the store just returns copies of the real dictionaries and any mutations are not reflected in the real document on disk. This commit gets around this by saving the mutated dictionary back to the collection once the code is finished updating it.


Originally submitted as PR at mongomock#805

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions