Sequoiadb sdb = new Sequoiadb("192.168.23.57:50000");
sdb.Connect("", "");
// The collection space name
string csName = "sample";
// The collection name
string cName = "sample";
// connect
CollectionSpace cs;
if (sdb.IsCollectionSpaceExist(csName))
cs = sdb.GetCollecitonSpace(csName);
else
cs = sdb.CreateCollectionSpace(csName);
DBCollection coll = null;
if (cs.IsCollectionExist(cName))
coll = cs.GetCollection(cName);
else
coll = cs.CreateCollection(cName);
// delete all records from the collection
BsonDocument bson = new BsonDocument();
coll.Delete(bson);
String[] record = new String[4];
record[0] = "{cust_id:\"A123\",amount:500,status:\"A\"}";
record[1] = "{cust_id:\"A123\",amount:250,status:\"A\"}";
record[2] = "{cust_id:\"B212\",amount:200,status:\"A\"}";
record[3] = "{cust_id:\"A123\",amount:300,status:\"D\"}";
// insert record into database
for (int i = 0; i < record.Length; i++)
{
BsonDocument obj = new BsonDocument();
obj = BsonDocument.Parse(record[i]);
Console.WriteLine("Record is: " + obj.ToString());
coll.Insert(obj);
}
//准备update
BsonDocument updater = new BsonDocument();
BsonDocument matcher = new BsonDocument();
BsonDocument modifier = new BsonDocument();
BsonDocument hint = new BsonDocument();
//条件
matcher.Add("cust_id", new BsonDocument("$et", "A123"));
//更新。
updater.Add("amount", "1000");
updater.Add("status", "C");
modifier.Add("$set", updater);
//update
coll.Update(matcher, modifier, hint);
System.Console.ReadLine();