My mongoDB collection has some records like:
{ "_id" : ObjectId("4d99b276368394f5130022fc") }
{ "_id" : ObjectId("4d99b276368394f5130022fd") }
{ "_id" : ObjectId("4d99b276368394f5130022fe") }
{ "_id" : ObjectId("4d99b276368394f5130022ff") }
{ "_id" : ObjectId("4d99b27d368394f613002470") }
{ "_id" : ObjectId("4d99b27d368394f613002471") }
{ "_id" : ObjectId("4d99b27d368394f613002472") }
Since the last bytes of a BSON objectId are more or less sequential,I intend to seperate them in multiple channels , for example "Ending with specific letter of ObjectId".
( equivalent of RLIKE in MySql ). Since objectIds are bytes and not strings, my regex does not seem to work. I tried something like:
db.myColl.findOne( { "_id" : /b$/ } , { "_id":1} )
null
> db.myColl.findOne( { "_id" : /^4/ } , { "_id":1} )
null
Any suggestions to partition my data based on objectId ? like last letter of objectId or something else which gives more or less equal distribution ?
EDIT: I found one way which worked for me :
db.myColl.findOne({ $where: "this._id.toString()[23] == 1" } ) // gives me records with ObjectId ending with 1 .
Other suggestions are still welcome