Lironess
Lironess

Reputation: 843

Limit mongodb collection to 1 row

I'm using mongodb with c# driver, and I would like to limit my MongoCollection to maximum 1 row. How do I do that ?

Upvotes: 1

Views: 778

Answers (2)

GaTechThomas
GaTechThomas

Reputation: 6075

Since this is tagged as mongodb-csharp, FindOneAs or SetLimit may be helpful:

https://stackoverflow.com/a/6593345/284598

Upvotes: 0

JohnnyHK
JohnnyHK

Reputation: 311875

If you want to limit the collection itself to one row, you could use a capped collection with max: 1.

db.createCollection("mycoll", {capped:true, size:100000, max:1});

Upvotes: 1

Related Questions