mongoDB Collection LRU Policy +java - mongodb

I am new to mongoDB. I am working on building an application which requires implementing LRU policy on the collection. In the mongoDB site i see capped collections support FIFO. Is there any other collection which support LRU. Throught the documentation i see only capped collections in the site. Are there any other collections in mongoDb.
Are collections by default capped in mongodb?

MongoDB capped collections are the only kilobyte size-limited collections supported by the database. There is no built-in support for LRU or FIFO based on limiting to a particular number of documents.
Collections are not capped by default in MongoDB - a capped collection is a special case.

Related

Document level lock in mongodb

Is document level lock possible in mongodb 3.4?
My collection contains millions of documents. I have scenario where I want to delete some documents (based on some id criteria) in the collection, and while these documents are being deleted, they should not be accessible by other users.
The documents which I do not want to delete should be accessible by other users.
So, I want to lock a few documents (based on some id criteria) which I want to delete.
Or is there a another way to do the above?
Starting in MongoDB 3.2, the WiredTiger storage engine is the default storage engine.
WiredTiger uses document-level concurrency control for write operations. As a result, multiple clients can modify different documents of a collection at the same time.
db.collection.remove() supports multi-document transactions.
so I think using default write concern should be enough for you.
More reference can be found at MongoDB documentation

MongoDB capped collection performance

I am recently working on a time series data project to store some sensor data.To achieve maximum insertion/write throughput i used capped collection(As per the mongodb documentation capped collection will increase the read/write performance). when i test the collection for insertion/write of some thousand documents/records using python driver with capped collection without index against the normal collection, i couldn't see much difference in improvement in write performance of capped collection over normal collection. example is like i inserted 40K records on single thread using pymongo driver. capped collection took around 25.4 seconds and normal collection took 25.7 seconds.
Could anyone please explain me when can we achieve maximum insertion/write throughput of capped collection? Is this is the right choice for time series data collections?
Data stored into capped collections are rotated upon exceeding fixed size of capped collection .
Capped collections don't require any indexes as they preserve the insertion order and also data is retrieved in natural order same as order in which the database refers to documents on disk.Hence it offers high performance in insertion and data retrieval process.
For more detailed description related to Capped collections please refer the documentation as mentioned in URL
https://docs.mongodb.com/manual/core/capped-collections/

How does MongoDB distribute data across a cluster

I've read about sharding a collection in MongoDB. MongoDB lets me shard a collection explicitly by calling shardCollection method. There I can choose whether I want it to be rangely shareded or hashingly sharded.
My question is, what would happen if I didn't call the shardCollection method, and I had say 100 nodes?
Would MongoDB keep the collections intact and distribute them across the cluster?
Would MongoDB keep all the collections in a single node?
Do I completely not understand how this works?
A database can have a mixture of sharded and unsharded collections. Sharded collections are partitioned and distributed across shards in the cluster. As at MongoDB 3.4, each database has a primary shard where the unsharded collections are stored. If your deployment has a number of databases this may result in some distribution of unsharded collections, but there is no balancing activity for unsharded data. For more information on expected behaviours, see the Sharding section in the MongoDB manual.
If you are interested in distribution of unsharded collections within a sharded database, there is a relevant feature request you can watch/upvote in the MongoDB issue tracker: SERVER-939: Ability to distribute collections in a single DB.

Subscribing to a collection - that is not capped

I am aware that with a combination of capped collections and tailable cursors Mongo clients can subscribe to additions to the collection. This however introduces a few limitations:
When the collection is full, the oldest members are removed.
Existing members cannot be changed if they are not the same size. Cannot change the size of a document in a capped collection
Is there something more generic (such as RDBMS triggers) I can employ to listen to changes of all sorts happening to a Mongo collection?

mongodb capped collections with TTL

I have an application that allows users to chat with other users,
I only want to store X messages per each conversation, AND each message must be deleted after 1 month since its creation (TTL)
MongoDB support capped collections with TTL?
The documentation says:
https://docs.mongodb.org/manual/core/capped-collections/#automatically-remove-data-after-a-specified-period-of-time
For additional flexibility when expiring data, consider MongoDB’s TTL indexes, as described in Expire Data from Collections by Setting TTL. These indexes allow you to expire and remove data from normal collections using a special type, based on the value of a date-typed field and a TTL value for the index.
TTL Collections are not compatible with capped collections.
I think not, so, there is any alternative to accomplish it?
Thanks