2011-11-15 38 views

回答

2

的 「名稱」 讓唯一索引

for example, in shell: db.MyCollection.ensureIndex({"Name":1}, {unique = true}) 

添加InsertOptions

var options = new MongoInsertOptions (myCollection) { CheckElementNames = true, Flags = InsertFlags.ContinueOnError, SafeMode = SafeMode.True}; 

var res = myCollection.InsertBatch(value.Split(',').Where(o => !string.IsNullOrEmpty(o)).Select(o => new Client { Name = o.Trim() }), options); 
相關問題