Error trying to access a collection

6 views
Skip to first unread message

Michael Hawksworth

unread,
May 25, 2010, 3:49:17 PM5/25/10
to norm-m...@googlegroups.com
Hi folks

I am trying to use the following to read all the records from the admin database collection and drop them into a list(or something but that's not material)...

            using (var database = new MongoAdmin(mongoConnectionString))
            {
                var db = database.Database;

                var collection = db.GetCollection(theSelectedCollection);

                var numberOfRecords = collection.Count();
                var records = collection.Find();

                // display records in list...
            }

however it throws the following exception in the deserialiser.ReadObject(Type type) routine

Deserialization failed: type System.Object does not have a property named xxx

I've tried to dig through it and it is returning null from FindProperty() in the TypeHelper which causes it to then throw an error.

I have also tried using a query provider but get the same exception.

            using (var qp = MongoQueryProvider.Create(mongoConnectionString))
            {
                var selectedCollection = (string)this.listCollections.SelectedItems[0];

                var collection = qp.DB.GetCollection(theSelectedCollection);

                ...

Is it because I am using GetCollection() and not GetCollection<>()?

And if so what should the entry be for T when we are looking at admin collections and what GetCollection() is for?

Cheers.

Regards
Michael Hawksworth

Michael Hawksworth

unread,
May 25, 2010, 4:16:21 PM5/25/10
to norm-m...@googlegroups.com
Ok scratch some of that! Loosing the plot trying to do too many things
at once :( before I go on holiday :)

Simply I am trying to get all the records from a collection when I
don't know the structure, it's for a simple mongodb viewer I am
knocking together.

Any suggestions would be appreciated.

Michael.

--
Sent from my mobile device

Regards
Michael Hawksworth

wateenmooiedag

unread,
May 26, 2010, 1:38:14 PM5/26/10
to NoRM mongodb
Read here: http://stackoverflow.com/questions/2298870/mongodb-get-names-of-all-keys-in-collection

On 25 mei, 22:16, Michael Hawksworth <mghawkswo...@gmail.com> wrote:
> Ok scratch some of that! Loosing the plot trying to do too many things
> at once :( before I go on holiday :)
>
> Simply I am trying to get all the records from a collection when I
> don't know the structure, it's for a simple mongodb viewer I am
> knocking together.
>
> Any suggestions would be appreciated.
>
> Michael.
>

Andrew Theken

unread,
May 26, 2010, 3:24:21 PM5/26/10
to Michael Hawksworth, norm-m...@googlegroups.com
just do "GetCollection<Expando>("collectionName") and you'll get back "stuff"
//Andrew Theken



Regards
Michael Hawksworth

--
You received this message because you are subscribed to the Google Groups "NoRM mongodb" group.
To post to this group, send email to norm-m...@googlegroups.com.
To unsubscribe from this group, send email to norm-mongodb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/norm-mongodb?hl=en.


Andrew Theken

unread,
May 26, 2010, 4:37:31 PM5/26/10
to NoRM mongodb
I spoke too soon, this is an issue that another contributor brought
up, I am going to see what I can do to fix it and will post back to
the group when I have something.

On May 26, 3:24 pm, Andrew Theken <athe...@gmail.com> wrote:
> just do "GetCollection<Expando>("collectionName") and you'll get back
> "stuff"
> //Andrew Theken
>
> On Tue, May 25, 2010 at 4:16 PM, Michael Hawksworth

> <mghawkswo...@gmail.com>wrote:


>
>
>
> > Ok scratch some of that! Loosing the plot trying to do too many things
> > at once :( before I go on holiday :)
>
> > Simply I am trying to get all the records from a collection when I
> > don't know the structure, it's for a simple mongodb viewer I am
> > knocking together.
>
> > Any suggestions would be appreciated.
>
> > Michael.
>

> > norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsubscribe@google groups.com>

Andrew Theken

unread,
May 26, 2010, 6:40:29 PM5/26/10
to NoRM mongodb
Micheal,

If you pull the latest from my repo, your code should work. Let us know what you find.

//Andrew Theken


To unsubscribe from this group, send email to norm-mongodb...@googlegroups.com.

Michael Hawksworth

unread,
May 27, 2010, 12:05:11 AM5/27/10
to Andrew Theken, NoRM mongodb
Thanks Andrew.

I'll have to have a look when I get back from Holiday (Wife seems to think I shouldn't take my laptop for some reason, odd I know!)

Great work by the way. Mongo is a learning curve but with NoRM and this group it is fun.  I'm really impressed with the commitment you guys have given to this.

Regards
Michael Hawksworth

Andrew Theken

unread,
May 27, 2010, 12:55:50 AM5/27/10
to Michael Hawksworth, NoRM mongodb
your wife is right, don't take your laptop on vacation (I should learn this lesson!)

and thanks, it really has been awesome to get so much help on the project, I think users keep us motivated. :-)

// Andrew Theken
Reply all
Reply to author
Forward
0 new messages