How can I change an objects id? It doesn't seem to be just a regular attribute, so I'm not sure if I'm able to update that value?
I'm using Ruby with Mongoid, but I can't figure out how using just the ruby driver, any help would be appreciated!
MongoDB won't let you update the _id
field of a document, but you can delete the document and reinsert it with a new _id
value.
So when you create the items; you can specify your own ID; however you can't change it once it's been created as it's a unique identifier for the row.
A bit more on the Object Id
If you want to specify them when creating your items you can do: {_id: 'YourUniqueID'} which will override it. More information in that above link.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With