Replace default _id

11 views
Skip to first unread message

Pat Ferrel

unread,
May 7, 2017, 12:22:42 PM5/7/17
to mongodb-casbah-users
I'd like to use a unique string per collection to id a doc. 

I know I should use collection.createIndex but I don't understand the scaladocs.

If my case class is :

case class GroupParams (
  _id: String,
  //groupId: String,
  testPeriodStart: DateTime, // ISO8601 date
  variants: Seq[String], //["17","18"]
  testPeriodEnd: Option[DateTime])

and I will always use the _id to reference a particular document (no need for _id: ObjectId).

I don't care about sorting/ordering since these will only be accessed as individual docs, never cursored through. There seems no reason to have the overhead of another index on the default  _id: ObjectId.

How to I create the index on the collection with  _id: String using Casbah? If I should create a new index and leave the default alone can you show how to do this?

Ross Lawley

unread,
May 8, 2017, 11:44:05 AM5/8/17
to mongodb-ca...@googlegroups.com
Hi Pat,

The default _id is fine, it can handle any BSON type so strings will be fine.

Ross

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

Pat Ferrel

unread,
May 8, 2017, 3:14:33 PM5/8/17
to mongodb-casbah-users
so I don't need to change anything, just make _id: String and since _id is the primary index and since it is a String Mongo will handle everything? No need to call createIndex? Because the way I would call is

 groups.createIndex(new BasicDBObject("_id",1))

Which would say nothing about the type for _id

Ross Lawley

unread,
May 8, 2017, 4:29:55 PM5/8/17
to mongodb-ca...@googlegroups.com
Hi,

Thats correct _id is the primary key and an automatic index, so nothing to do on your side.

Just to let you know there is a newer official MongoDB Scala driver which is an idiomatic asynchronous driver. So if you want an asynchronous Scala driver please check it out.

All the best,

Ross

On Mon, May 8, 2017 at 8:14 PM, Pat Ferrel <p...@occamsmachete.com> wrote:
so I don't need to change anything, just make _id: String and since _id is the primary index and since it is a String Mongo will handle everything? No need to call createIndex? Because the way I would call is

 groups.createIndex(new BasicDBObject("_id",1))

Which would say nothing about the type for _id


On Monday, May 8, 2017 at 8:44:05 AM UTC-7, Ross Lawley wrote:
Hi Pat,

The default _id is fine, it can handle any BSON type so strings will be fine.

Ross
On Sun, May 7, 2017 at 5:22 PM, Pat Ferrel <p...@occamsmachete.com> wrote:
I'd like to use a unique string per collection to id a doc. 

I know I should use collection.createIndex but I don't understand the scaladocs.

If my case class is :

case class GroupParams (
  _id: String,
  //groupId: String,
  testPeriodStart: DateTime, // ISO8601 date
  variants: Seq[String], //["17","18"]
  testPeriodEnd: Option[DateTime])

and I will always use the _id to reference a particular document (no need for _id: ObjectId).

I don't care about sorting/ordering since these will only be accessed as individual docs, never cursored through. There seems no reason to have the overhead of another index on the default  _id: ObjectId.

How to I create the index on the collection with  _id: String using Casbah? If I should create a new index and leave the default alone can you show how to do this?

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pat Ferrel

unread,
May 8, 2017, 4:42:15 PM5/8/17
to mongodb-casbah-users
Cool, does the MongoDB Scala driver replace Casbah? 
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ross Lawley

unread,
May 8, 2017, 4:53:33 PM5/8/17
to mongodb-ca...@googlegroups.com
Hi,

Its more of a modern alternative, rather than a replacement. Built upon the newer async Java driver the Scala driver follows the latest cross driver common API initiatives.

Ross

To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rizwan Sharif

unread,
Aug 1, 2017, 5:06:04 PM8/1/17
to mongodb-casbah-users
Hi Ross,

Would casbah driver be updated for future versions of mongodb ? Or do you suggest we migrate to Scala Driver? You answer on this jira ticket : https://jira.mongodb.org/browse/CASBAH-199 makes me infer that casbah lacks the full support for 3.4 as well. 

Ross Lawley

unread,
Aug 2, 2017, 5:30:02 AM8/2/17
to mongodb-ca...@googlegroups.com
Hi Rizwan,

There are no current plans to update Casbah to include new features from newer versions of MongoDB.  This is because it relies on a deprecated API in the Mongo Java Driver, which also doesn't support all the new features.  The Mongo Scala Driver will be support future MongoDB versions, as it relies on the new Java APIs.

All the best,

Ross

Hi Ross,

To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

--
You received this message because you are subscribed to the Google Groups "mongodb-casbah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-casbah-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages