The best solution would be to leave the _id column as it is, and have separate userId and folderId fields in your document or create a separate field in which they are combined.
As for whether it will be "just as fast" ... it depends on your request, but for ordering the "date of creation" of the document, for example, you lose the ability to simply order by _id , you also lose the benefits of sharding and distribution .
However, if you want to use both of these identifiers for your _id , there is another option ...
In fact, you can use both options, but leave them separate ... for example, this is a valid _id :
> var doc = { "_id" : { "userID" : 12345, "folderID" : 5152 }, "field1" : "test", "field2" : "foo" }; > db.crazy.save(doc); > db.crazy.findOne(); { "_id" : { "userID" : 12345, "folderID" : 5152 }, "field1" : "test", "field2" : "foo" } >
source share