mongodbpublish-subscribecapped-collections

Pub/Sub MongoDB Capped collection


If i try to update capped collection it returns "Capped collections can't be updated". What I came to know is capped collections can't be updated.

I'm newbie, and for my project requirements I have to notify client about any data updates at server and I'm using NodeJS

Is there any way to update capped collection. Thanks in advance :)


Solution

  • According to the docs ...

    Document Size

    Changed in version 3.2.

    If an update or a replacement operation changes the document size, the operation will fail.

    Capped collections are intended for usage patterns such as: 'write once and then read as long as it is available' (or, as the docs put it: "Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order") so although updates are supported (as long as they do not change document size) they aren't typically expected on a capped collection.

    If you need to update this collection and you cannot be certain that the updates will not change collection size then the collection should not be capped. Perhaps you should reconsider (a) whether the collection should be continue to be a capped colleciotn or (b) why you need to update the collection.