RamiAwar/Mongomantic

updating and deleting objects?

Opened this issue ยท 2 comments

Checklist

  • [ x ] I've searched the project's issues.

โ“ Question

How does updating an object work?

๐Ÿ“Ž Additional context

I managed to get Mongomantic working and I can get objects from the database and also save new objects to the database. But how does updating and deleting work?
if i do this:

u= UserRepository.get(username="aaa")
u.username = str(random.randint(0,10000))
UserRepository.save(u)

I'd expect it to update the existing user in the database, but this generates a new document with the new values.

As there doesn't seem to be any documentation on updating and deleting for now: What am I doing wrong here? How does updating and deleting work?

Hello @janolehuebner, thank you for your interest in our work!

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

Hey @janolehuebner! The way things work now is if the document already has a _id field, then the document in the DB will be overwritten by whatever you're saving. I want to change things to check if the document already exists however, and in that case only update the fields that have changed.

At that point, you'll be able to use doc.save(), and it would check if the document already exists, and if it does, would only update the existing fields.

That would cover your usecase right?