Skip to content

Instantly share code, notes, and snippets.

@house9
Created May 3, 2011 23:31
Show Gist options
  • Save house9/954461 to your computer and use it in GitHub Desktop.
Save house9/954461 to your computer and use it in GitHub Desktop.
Simple.Data with MongoDB
using Simple.Data;
using Simple.Data.MongoDB;
// connect
dynamic db = Database.Opener.OpenMongo("mongodb://localhost:27017/myDB");
// insert
dynamic user = new ExpandoObject();
user.FirstName = "Joe";
user.LastName = "Smith";
user.Email = "jsmith@test.com";
db.Users.Insert(user);
// find
dynamic existingUser = db.Users.FindByEmail("jsmith@test.com");
@jonathanconway
Copy link

Great library, but is there any way I can get every item in a collection, without filtering? I've tried everything I can think of, including 'db.Users' or 'db.Users.FindAll()', but nothing seems to work.

@house9
Copy link
Author

house9 commented Jul 8, 2011

I think it is FindAll() or FindByAll() or FindAllBy()
the wiki entry must have some typo because it uses both and one is definitely not correct
see https://github.com/markrendle/Simple.Data/wiki/Finding-data
haven't been working with c# for last few months and can't remember which one

@jonathanconway
Copy link

Thanks for the speedy reply!

I tried FindAll(), FindByAll(), FindAllBy() and FindBy(). All of them seem to throw exceptions except FindAll, so I'm guessing that FindAll() is the correct method name, and that the MongoDB adapter just doesn't implement it yet.

I'm going through the source code now to see if I can find where it's failing and fix it.

BTW, I realize it's not best practice to grab everything from a Mongo collection. Did you implement anything similar to say, "Limit()"? If not, I might try to implement that. Right now I just want to grab the latest 5 items from a collection.

@house9
Copy link
Author

house9 commented Jul 13, 2011

Not sure if you got it to work?
Maybe post at the authors repo https://github.com/craiggwilson/Simple.Data.MongoDB
I only messed around with this for a few days, and that was months ago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment