Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Storing and querying a 36 byte _id from C#
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
IanC  
View profile  
 More options Sep 11 2012, 7:26 am
From: IanC <ianr...@gmail.com>
Date: Tue, 11 Sep 2012 04:26:28 -0700 (PDT)
Local: Tues, Sep 11 2012 7:26 am
Subject: Storing and querying a 36 byte _id from C#

I have a use case where storing an _id that is a composite of the following
would be immensely useful:

   1. 96 bit int
   2. 96 bit int
   3. 96 bit int ObjectID

This works out as a 36 byte ASCII string.

I would like to query "Give me all documents where _id starts with {1}
concatenate {2}." This would return documents where _id matches components
1 & 2 above, with any 3. Being able to do range queries would be useful,
but I don't know if this is possible.
I'm using C# to access MongoDB. My first question is what data type should
I use? If I use a string, it will encode as UTF-16 (.Net's native type),
which is not plain binary, will inflate the size, and possibly confound
queries. Will a byte array work?

My second question is how do I query it? I don't believe regex will
accommodate the full ASCII 0 - 255 range.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Podkowinski  
View profile  
 More options Sep 11 2012, 8:23 am
From: Stefan Podkowinski <s.podkowin...@gmail.com>
Date: Tue, 11 Sep 2012 05:23:02 -0700 (PDT)
Local: Tues, Sep 11 2012 8:23 am
Subject: Re: Storing and querying a 36 byte _id from C#

Try the BSON Binary datatype for that. You should be able to create an
instance from a byte array in .net to create a $gt/$lt data range query.
Just make sure to add padding with zeros ($gt) or max values ($lt) for all
remaining bytes so you get a 36byte key for comparison.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
IanC  
View profile  
 More options Sep 11 2012, 8:39 am
From: IanC <ianr...@gmail.com>
Date: Tue, 11 Sep 2012 05:39:21 -0700 (PDT)
Local: Tues, Sep 11 2012 8:39 am
Subject: Re: Storing and querying a 36 byte _id from C#

Thanks. And if I want to use a "starts with" query, how would I do that?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Sep 11 2012, 11:44 am
From: craiggwilson <craiggwil...@gmail.com>
Date: Tue, 11 Sep 2012 08:44:25 -0700 (PDT)
Local: Tues, Sep 11 2012 11:44 am
Subject: Re: Storing and querying a 36 byte _id from C#

MongoDB supports composite id's as well, so you can leave the 3 components
you have split up, and then do any kind of query on them that is support by
those types.

{ _id : { "first" : 30345345, "second" : 3556654, "third" : ObjectId("...")


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
IanC  
View profile  
 More options Sep 11 2012, 11:57 am
From: IanC <ianr...@gmail.com>
Date: Tue, 11 Sep 2012 08:57:43 -0700 (PDT)
Local: Tues, Sep 11 2012 11:57 am
Subject: Re: Storing and querying a 36 byte _id from C#

Ok, even better. So I could do an equals or range on first and second.
Since I'm dealing with 96 bit ints for each, would I use ObjectID to cast
for all 3? Would you mind providing a sample query please.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Sep 11 2012, 12:55 pm
From: craiggwilson <craiggwil...@gmail.com>
Date: Tue, 11 Sep 2012 09:55:32 -0700 (PDT)
Local: Tues, Sep 11 2012 12:55 pm
Subject: Re: Storing and querying a 36 byte _id from C#

No, I would use an integer for the first 2 and an ObjectId for the 3rd.

db.foos.find({ "_id.first" : { $gt : 0 }, "_id.second" : { $lt : 100 }})

would find all the documents with the first component of the _id is greater
than 0 and the second component of the _id is less than 100.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Sep 11 2012, 12:57 pm
From: craiggwilson <craiggwil...@gmail.com>
Date: Tue, 11 Sep 2012 09:57:07 -0700 (PDT)
Local: Tues, Sep 11 2012 12:57 pm
Subject: Re: Storing and querying a 36 byte _id from C#

Also, remember that the _id can never change for a document after it is
set.  So, if you need these to be mutable, then store these as a normal
document and use a surrogate key (probably and ObjectId) as the primary key.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
IanC  
View profile  
 More options Sep 11 2012, 6:24 pm
From: IanC <ianr...@gmail.com>
Date: Tue, 11 Sep 2012 15:24:33 -0700 (PDT)
Local: Tues, Sep 11 2012 6:24 pm
Subject: Re: Storing and querying a 36 byte _id from C#

Ok, if I used integers, I'd need 5 components for _id since we don't have
96 bit ints. Would you recommend this over binary?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Sep 12 2012, 8:22 am
From: craiggwilson <craiggwil...@gmail.com>
Date: Wed, 12 Sep 2012 05:22:04 -0700 (PDT)
Local: Wed, Sep 12 2012 8:22 am
Subject: Re: Storing and querying a 36 byte _id from C#

It depends on your needs.  Do you need to dynamically query these pieces?
 Can you run the queries you need storing them as binary?  I'd test it out
and see if you can accomplish what you need by storing things as binary or
a string.  Either way, you'll have your answer.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Sep 12 2012, 8:22 am
From: craiggwilson <craiggwil...@gmail.com>
Date: Wed, 12 Sep 2012 05:22:59 -0700 (PDT)
Local: Wed, Sep 12 2012 8:22 am
Subject: Re: Storing and querying a 36 byte _id from C#

Also, if you go the binary route, you can't use the Aggregation Framework
with that document.  If that is a concern for you, then don't use binary.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »