public static bool AddStudent(Student student) { var query = Query.EQ("StuNo", student.StuNo); if (collection.Find(query).Count() > 0) return false; else { collection.Insert<Student>(student); return true; } }
public static void Update(Student student) { var option = new DocumentSerializationOptions(false); option.SerializeIdFirst = false; collection.Update(new QueryDocument { { "_id", student.Id } }, new UpdateDocument { { "$set", new BsonDocument { {"StuNo", student.StuNo }, {"Name", student.Name}, {"Major", student.Major}, {"Class", student.Class}} }}); }