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
C++ Model tutorial...
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
  6 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
 
PlugGulp  
View profile  
 More options Sep 2 2012, 10:31 pm
From: PlugGulp <plug.g...@gmail.com>
Date: Sun, 2 Sep 2012 19:31:26 -0700 (PDT)
Local: Sun, Sep 2 2012 10:31 pm
Subject: [Newbie] C++ Model tutorial...

Hi,

I am new to MongoDB. I was browsing the code of C++ driver and found the
class Model. How to use this class and when and why to use it? Please could
you provide example or point me to any tutorial that will explain that.

Thanks and regards,

~Plug


 
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.
Adam C  
View profile  
 More options Sep 3 2012, 12:28 pm
From: Adam C <ad...@10gen.com>
Date: Mon, 3 Sep 2012 09:28:58 -0700 (PDT)
Local: Mon, Sep 3 2012 12:28 pm
Subject: Re: [Newbie] C++ Model tutorial...

From the docs:

"Model is a base class for defining objects which are serializable to the
Mongo database via the database driver"

http://api.mongodb.org/cplusplus/2.2.0/classmongo_1_1_model.html#details

If you are looking for higher level modeling (data structures etc.) the C++
driver won't have anything like that.

Adam


 
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.
PlugGulp  
View profile  
 More options Sep 3 2012, 6:43 pm
From: PlugGulp <plug.g...@gmail.com>
Date: Mon, 3 Sep 2012 15:43:20 -0700 (PDT)
Local: Mon, Sep 3 2012 6:43 pm
Subject: Re: [Newbie] C++ Model tutorial...

On Monday, September 3, 2012 5:28:58 PM UTC+1, Adam C wrote:

> From the docs:

> "Model is a base class for defining objects which are serializable to the
> Mongo database via the database driver"

> http://api.mongodb.org/cplusplus/2.2.0/classmongo_1_1_model.html#details

Thanks for the reply. I completely understand that the Model class is for
serialization and deserialization. But my question was related to how it is
used, when (i.e. during what circumstances) and why it is used when there
is already a BSONObjBuilder.

> If you are looking for higher level modeling (data structures etc.) the
> C++ driver won't have anything like that.

I think thats the reason the Model class is provided. But I am not sure
about that. For e.g. say I define a class as such:

class MyModel : public mongo::Model
{
     public:
         virtual const char* getNS(); // Implemented by this class.
         virtual void serialize(BSONObjBuilder<http://api.mongodb.org/cplusplus/current/classmongo_1_1_b_s_o_n_obj_b...>&to); // Implemented by this class. Pumps this class's member variables
into the BOB.
         virtual void unserialize(const BSONObj<http://api.mongodb.org/cplusplus/current/classmongo_1_1_b_s_o_n_obj.html>&from); // Implemented by this class. Extracts data from the BOB and stores
into this class's member variables.
         virtual string modelServer(); // Implemented by this class.

     private:
         // Member variables representing data of this model.

};

Now, once I implement the MyModel class, how do I use it? And when and why
should I use it? There is no example/document/tutorial explaining that.

Thanks and regards,

~Plug

Adam


 
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.
William Z  
View profile  
 More options Sep 5 2012, 2:16 pm
From: William Z <william.z...@10gen.com>
Date: Wed, 5 Sep 2012 11:16:55 -0700 (PDT)
Local: Wed, Sep 5 2012 2:16 pm
Subject: Re: [Newbie] C++ Model tutorial...

The "Model" class is an optional Object to Document mapper for C++.  You
would use it if you wanted to extend and existing class to have built-in
methods to save itself from MongoDB and to load itself from MongoDB.

When you implemented your inherited class, you'd write the 'serialize()'
and 'unserialize()' methods to use BSONObjBuilder to build a BSON
representation of this class.  

Once you have an instance of the class, you can call the 'load()' method to
instantiate the class from the values stored in MongoDB, and call the
'save()' method to save the class values into MongoDB for later use.

Use of the "Model" class is definitely optional, and not recommended for
beginners.  Unfortunately, I could not find any further documentation on
the use of this class, nor could I find any tutorial examples.

Let me know if you have further questions.

 -William


 
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.
PlugGulp  
View profile  
 More options Sep 5 2012, 4:56 pm
From: PlugGulp <plug.g...@gmail.com>
Date: Wed, 5 Sep 2012 13:56:55 -0700 (PDT)
Local: Wed, Sep 5 2012 4:56 pm
Subject: Re: [Newbie] C++ Model tutorial...

Hello William,

Thank you for the reply. Yesterday I wrote a small piece of code to
understand the usage of Model class. It is actually similar to what you
described in your post. I am attaching the source file here. Please could
you review and comment on the code. Is that the correct way of using Model
class?

Thanks and regards,

~Plug

  main_t.cpp
2K Download

 
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.
William Zola  
View profile  
 More options Oct 10 2012, 1:29 pm
From: William Zola <william.z...@10gen.com>
Date: Wed, 10 Oct 2012 10:29:46 -0700 (PDT)
Local: Wed, Oct 10 2012 1:29 pm
Subject: Re: [Newbie] C++ Model tutorial...

Hi Plug!

Unfortunately, I'm not a good enough C++ programmer to review your code.  
You may, however, find this SERVER ticket relevant:  
https://jira.mongodb.org/browse/SERVER-7314

 -William


 
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 »